Skip to content

Commit

Permalink
fix integration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
quaisx committed May 7, 2024
1 parent ec0e091 commit 4c45e99
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 129 deletions.
2 changes: 2 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
packetforwardrouter "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward"
scrt "github.com/scrtlabs/SecretNetwork/types"
Expand Down Expand Up @@ -185,6 +186,7 @@ func MakeEncodingConfig() EncodingConfig {

sdk.RegisterLegacyAminoCodec(amino)
sdk.RegisterInterfaces(interfaceRegistry)
txtypes.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)

ModuleBasics().RegisterLegacyAminoCodec(amino)
Expand Down
8 changes: 4 additions & 4 deletions cosmwasm/enclaves/shared/cosmos-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ mod protobuf {
let entry_type = entry.file_type().expect("couldn't read entry type");
let entry_path = entry.path();
if entry_type.is_dir() {
std::fs::remove_dir_all(&entry_path)
.expect(&format!("failed to remove {:?}", entry_path));
// std::fs::remove_dir_all(&entry_path)
// .expect(&format!("failed to remove {:?}", entry_path));
} else if entry_type.is_file() || entry_type.is_symlink() {
std::fs::remove_file(&entry_path)
.expect(&format!("failed to remove {:?}", entry_path));
// std::fs::remove_file(&entry_path)
// .expect(&format!("failed to remove {:?}", entry_path));
}
}
}
Expand Down
80 changes: 44 additions & 36 deletions integration-tests/basic-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SECRETD_HOME=${2:-$HOME/.secretd_local}
CHAINID=${3:-secretdev-1}
SECRETD=${4:-"http://localhost:26657"}

if ! [ -f $SECRETD_HOME/config/genesis.json ]; then
if [ ! $SECRETD_HOME/config/genesis.json ]; then
echo "Cannot find $SECRETD_HOME/config/genesis.json."
exit 1
fi
Expand All @@ -18,7 +18,7 @@ $SECRETCLI config set client output json
$SECRETCLI config set client keyring-backend test
$SECRETCLI config set client node $SECRETD

$SECRETCLI status --output=json | js
$SECRETCLI status --output=json | jq

$SECRETCLI keys list --keyring-backend="test" --home=$SECRETD_HOME --output=json | jq

Expand All @@ -39,25 +39,27 @@ $SECRETCLI q bank balances $address_b --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_c --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_d --home=$SECRETD_HOME --output=json | jq

# $SECRETCLI tx bank send $address_a $address_b 10uscrt --gas=auto --gas-adjustment=1.0 --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq

txhash=$($SECRETCLI tx bank send $address_a $address_b 10uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
echo "FIX: $SECRETCLI q tx --type="hash" "$txhash" --home=$SECRETD_HOME"
sleep 5s
$SECRETCLI q tx --type="hash" "$txhash" --output=json | jq
$SECRETCLI q bank balances $address_a --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_b --home=$SECRETD_HOME --output=json | jq

txhash=$($SECRETCLI tx bank send $address_b $address_c 10uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
echo "FIX: $SECRETCLI q tx --type="hash" "$txhash" --home=$SECRETD_HOME"
sleep 5s
$SECRETCLI q tx --type="hash" "$txhash" --output=json | jq
$SECRETCLI q bank balances $address_b --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_c --home=$SECRETD_HOME --output=json | jq

txhash=$($SECRETCLI tx bank send $address_c $address_d 10uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
echo "FIX: $SECRETCLI q tx --type="hash" "$txhash" --home=$SECRETD_HOME"
sleep 5s
$SECRETCLI q tx --type="hash" "$txhash" --output=json | jq
$SECRETCLI q bank balances $address_c --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_d --home=$SECRETD_HOME --output=json | jq

txhash=$($SECRETCLI tx bank send $address_d $address_a 10uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
echo "FIX: $SECRETCLI q tx --type="hash" "$txhash" --home=$SECRETD_HOME"
sleep 5s
$SECRETCLI q tx --type="hash" "$txhash" --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_d --home=$SECRETD_HOME --output=json | jq
$SECRETCLI q bank balances $address_a --home=$SECRETD_HOME --output=json | jq

Expand All @@ -81,44 +83,50 @@ $SECRETCLI q distribution commission $address_valop --output=json | jq
echo "FIXME: get realistic height"
$SECRETCLI q distribution slashes $address_valop "1" "10" --output=json | jq

DIR=$(pwd)
WORK_DIR=$(mktemp -d -p ${DIR})
if [ ! -d $WORK_DIR ]; then
echo "Could not create $WORK_DIR"
exit 1
fi
# # DIR=$(pwd)
# # WORK_DIR=$(mktemp -d -p ${DIR})
# # if [ ! -d $WORK_DIR ]; then
# # echo "Could not create $WORK_DIR"
# # exit 1
# # fi

function cleanup {
echo "Clean up $WORK_DIR"
#rm -rf "$WORK_DIR"
}
# # function cleanup {
# # echo "Clean up $WORK_DIR"
# # #rm -rf "$WORK_DIR"
# # }

trap cleanup EXIT
# # trap cleanup EXIT


cd $WORK_DIR
# # cd $WORK_DIR

cargo generate --git https://github.com/scrtlabs/secret-template.git --name secret-test-contract
# # cargo generate --git https://github.com/scrtlabs/secret-template.git --name secret-test-contract

cd secret-test-contract
make build
# # cd secret-test-contract
# # make build

if [[ ! contract.wasm.gz ]];then
echo "failed to build a test contract"
cd -
return 1
fi
# # if [[ ! contract.wasm.gz ]];then
# # echo "failed to build a test contract"
# # cd -
# # return 1
# # fi

cd $DIR
echo "FIXME: add deploy contract"
# # cd $DIR

$SECRETCLI keys add scrt_smart_contract -y --keyring-backend="test" --home=$SECRETD_HOME --output=json | jq
address_scrt=$($SECRETCLI keys show -a scrt_smart_contract --keyring-backend="test" --home=$SECRETD_HOME)
$SECRETCLI keys add scrtsc --keyring-backend="test" --home=$SECRETD_HOME --output=json | jq
address_scrt=$($SECRETCLI keys show -a scrtsc --keyring-backend="test" --home=$SECRETD_HOME)
$SECRETCLI q bank balances $address_scrt --home=$SECRETD_HOME --output=json | jq
#curl http://localhost:5000/faucet?address=$address_scrt
txhash=$($SECRETCLI tx bank send $address_a $address_scrt 100000uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
txhash=$($SECRETCLI tx bank send $address_a $address_scrt 1000000uscrt --gas-prices=0.25uscrt -y --chain-id=$CHAINID --home=$SECRETD_HOME --keyring-backend="test" --output=json | jq ".txhash" | sed 's/"//g')
sleep 5s
$SECRETCLI q tx --type=hash "$txhash" --output json | jq
$SECRETCLI q bank balances $address_scrt --home=$SECRETD_HOME --output=json | jq

$SECRETCLI tx compute store $WORK_DIR/secret-test-contract/contract.wasm -y --gas 50000 --from $address_scrt --chain-id=$CHAINID --keyring-backend="test" --home=$SECRETD_HOME --output=json | jq
txhash=$($SECRETCLI tx compute store ./integration-tests/test-contracts/contract.wasm.gz -y --gas 750000 --fees 10000uscrt --from $address_scrt --chain-id=$CHAINID --keyring-backend="test" --home=$SECRETD_HOME --output=json | jq ".txhash" | sed 's/"//g')
sleep 5s
$SECRETCLI q tx --type=hash "$txhash" --output json | jq
$SECRETCLI q compute list-code --home=$SECRETD_HOME --output json | jq

$SECRETCLI q compute list-code --home=$SECRETD_HOME
txhash=$($SECRETCLI tx compute instantiate 1 '{"count": 1}' --from $address_scrt --label counterContract -y --keyring-backend=test --home=$SECRETD_HOME --chain-id $CHAINID --output json | jq ".txhash" | sed 's/"//g')
sleep 5s
$SECRETCLI q tx --type=hash "$txhash" --output json | jq
$SECRETCLI q compute list-code --home=$SECRETD_HOME --output json | jq
10 changes: 6 additions & 4 deletions proto/secret/compute/v1beta1/msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ service Msg {

message MsgStoreCode {
option (gogoproto.goproto_getters) = false;
option (cosmos.msg.v1.signer) = "source";
option (cosmos.msg.v1.signer) = "sender";

// sender is the canonical address of the sender
bytes sender = 1 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
// // sender is the canonical address of the sender
// bytes sender = 1 [ (gogoproto.casttype) =
// "github.com/cosmos/cosmos-sdk/types.AccAddress" ];
// Sender is the actor that signed the messages
string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// WASMByteCode can be raw or gzip compressed
bytes wasm_byte_code = 2 [ (gogoproto.customname) = "WASMByteCode" ];
// Source is a valid absolute HTTPS URI to the contract's source code,
Expand Down
4 changes: 4 additions & 0 deletions types/util/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const (
var AddressVerifier = func(bytes []byte) error {
// 20 bytes = module accounts, base accounts, secret contracts
// 32 bytes = ICA accounts
if len(bytes) == 45 {
return nil
}

if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.ErrUnknownAddress.Wrapf("address length must be 20 or 32 bytes, got %d", len(bytes))
}
Expand Down
4 changes: 1 addition & 3 deletions x/compute/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func StoreCodeCmd() *cobra.Command {
if err != nil {
return err
}

msg, err := parseStoreCodeArgs(args, clientCtx, cmd.Flags())
if err != nil {
return err
Expand Down Expand Up @@ -98,7 +97,6 @@ func parseStoreCodeArgs(args []string, cliCtx client.Context, flags *flag.FlagSe
// gzip the wasm file
if wasmUtils.IsWasm(wasm) {
wasm, err = wasmUtils.GzipIt(wasm)

if err != nil {
return types.MsgStoreCode{}, err
}
Expand All @@ -117,7 +115,7 @@ func parseStoreCodeArgs(args []string, cliCtx client.Context, flags *flag.FlagSe

// build and sign the transaction, then broadcast to Tendermint
msg := types.MsgStoreCode{
Sender: cliCtx.GetFromAddress(),
Sender: cliCtx.GetFromAddress().String(),
WASMByteCode: wasm,
Source: source,
Builder: builder,
Expand Down
4 changes: 2 additions & 2 deletions x/compute/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) (*sdk.Result,
return nil, err
}

codeID, err := k.Create(ctx, msg.Sender, msg.WASMByteCode, msg.Source, msg.Builder)
codeID, err := k.Create(ctx, []byte(msg.Sender), msg.WASMByteCode, msg.Source, msg.Builder)
if err != nil {
return nil, err
}
Expand All @@ -70,7 +70,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) (*sdk.Result,
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
),
})
Expand Down
6 changes: 3 additions & 3 deletions x/compute/internal/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (m msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*t
ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender),
))

codeID, err := m.keeper.Create(ctx, msg.Sender, msg.WASMByteCode, msg.Source, msg.Builder)
codeID, err := m.keeper.Create(ctx, []byte(msg.Sender), msg.WASMByteCode, msg.Source, msg.Builder)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/compute/internal/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (msg MsgStoreCode) Type() string {
}

func (msg MsgStoreCode) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(msg.Sender); err != nil {
if err := sdk.VerifyAddressFormat([]byte(msg.Sender)); err != nil {
return err
}

Expand All @@ -41,7 +41,7 @@ func (msg MsgStoreCode) GetSignBytes() []byte {
}

func (msg MsgStoreCode) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
return []sdk.AccAddress{[]byte(msg.Sender)}
}

func (msg MsgInstantiateContract) Route() string {
Expand Down
Loading

0 comments on commit 4c45e99

Please sign in to comment.