diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a1a661411..97079d9df 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,10 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | cargo --version @@ -80,7 +83,10 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | cargo --version @@ -128,6 +134,10 @@ jobs: with: name: contract.wasm path: ./x/compute/internal/keeper/testdata/test-contract/contract.wasm + - uses: actions/upload-artifact@v2 + with: + name: v1-contract.wasm + path: ./x/compute/internal/keeper/testdata/v1-sanity-contract/contract.wasm - uses: actions/upload-artifact@v2 with: name: enclave @@ -174,6 +184,10 @@ jobs: - uses: actions/download-artifact@v2 with: name: contract.wasm + - uses: actions/download-artifact@v2 + with: + name: v1-contract.wasm + path: ./x/compute/internal/keeper/testdata/v1-sanity-contract - uses: actions/download-artifact@v2 with: name: contract_with_floats.wasm @@ -185,12 +199,14 @@ jobs: name: static-too-high-initial-memory.wasm - name: Setup Files run: | + find "$(pwd)" -name \*.wasm cp libgo_cosmwasm.so ./go-cosmwasm/api/libgo_cosmwasm.so cp librust_cosmwasm_enclave.signed.so ./go-cosmwasm/librust_cosmwasm_enclave.signed.so cp contract.wasm ./x/compute/internal/keeper/testdata/test-contract/contract.wasm cp too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/test-contract/too-high-initial-memory.wasm cp contract_with_floats.wasm ./x/compute/internal/keeper/testdata/test-contract/contract_with_floats.wasm cp static-too-high-initial-memory.wasm ./x/compute/internal/keeper/testdata/test-contract/static-too-high-initial-memory.wasm + find "$(pwd)" -name \*.wasm - name: Test x/registration run: | source "$HOME/.sgxsdk/sgxsdk/environment" @@ -234,9 +250,13 @@ jobs: with: path: ~/.cache/sccache key: ${{ runner.os }}-sccache - - run: rustup component add rust-src clippy + - run: | + rustup component add rust-src clippy + cd cosmwasm/enclaves/execute/ + rustup component add rust-src clippy - name: Install xargo run: | + cd cosmwasm/enclaves/execute/ cargo --version rustc --version cargo +stable install xargo --version 0.3.25 diff --git a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs index e2eeee296..838e3fa7c 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs @@ -2,6 +2,7 @@ use log::*; use enclave_ffi_types::{Ctx, EnclaveError}; +use crate::contract_validation::{ReplyParams, ValidatedMessage}; use crate::external::results::{HandleSuccess, InitSuccess, QuerySuccess}; use crate::wasm::CosmWasmApiVersion; use cosmos_proto::tx::signing::SignMode; @@ -108,7 +109,10 @@ pub fn init( let decrypted_msg = secret_msg.decrypt()?; - let (validated_msg, reply_params) = validate_msg(&decrypted_msg, contract_code.hash(), None)?; + let ValidatedMessage { + validated_msg, + reply_params, + } = validate_msg(&decrypted_msg, contract_code.hash(), None)?; trace!( "init input after decryption: {:?}", @@ -142,8 +146,7 @@ pub fn init( // TODO: ref: https://github.com/CosmWasm/cosmwasm/blob/b971c037a773bf6a5f5d08a88485113d9b9e8e7b/packages/std/src/query.rs#L13 let output = encrypt_output( output, - secret_msg.nonce, - secret_msg.user_public_key, + &secret_msg, &canonical_contract_address, &env_v010.contract_code_hash, reply_params, @@ -167,25 +170,14 @@ pub fn init( }) } -pub struct TaggedBool { - b: bool, +pub struct ParsedMessage { + pub should_validate_sig_info: bool, + pub was_msg_encrypted: bool, + pub secret_msg: SecretMessage, + pub decrypted_msg: Vec, + pub contract_hash_for_validation: Option>, } -impl From for TaggedBool { - fn from(b: bool) -> Self { - TaggedBool { b } - } -} - -impl Into for TaggedBool { - fn into(self) -> bool { - self.b - } -} - -type ShouldValidateSigInfo = TaggedBool; -type WasMessageEncrypted = TaggedBool; - pub fn reduct_custom_events(reply: &mut Reply) { reply.result = match &reply.result { SubMsgResult::Ok(r) => { @@ -228,16 +220,7 @@ pub fn parse_message( message: &[u8], sig_info: &SigInfo, handle_type: &HandleType, -) -> Result< - ( - ShouldValidateSigInfo, - WasMessageEncrypted, - SecretMessage, - Vec, - Option>, - ), - EnclaveError, -> { +) -> Result { let orig_secret_msg = SecretMessage::from_slice(message)?; return match handle_type { @@ -247,13 +230,13 @@ pub fn parse_message( base64::encode(&message) ); let decrypted_msg = orig_secret_msg.decrypt()?; - Ok(( - ShouldValidateSigInfo::from(true), - WasMessageEncrypted::from(true), - orig_secret_msg, + Ok(ParsedMessage { + should_validate_sig_info: true, + was_msg_encrypted: true, + secret_msg: orig_secret_msg, decrypted_msg, - None, - )) + contract_hash_for_validation: None, + }) } HandleType::HANDLE_TYPE_REPLY => { @@ -315,13 +298,13 @@ pub fn parse_message( EnclaveError::FailedToSerialize })?; - return Ok(( - ShouldValidateSigInfo::from(false), - WasMessageEncrypted::from(false), - reply_secret_msg, - serialized_reply, - None, - )); + return Ok(ParsedMessage { + should_validate_sig_info: false, + was_msg_encrypted: false, + secret_msg: reply_secret_msg, + decrypted_msg: serialized_reply, + contract_hash_for_validation: None, + }); } // Here we are sure the reply is OK because only OK is encrypted @@ -420,13 +403,15 @@ pub fn parse_message( msg: serialized_encrypted_reply, }; - Ok(( - ShouldValidateSigInfo::from(true), - WasMessageEncrypted::from(true), - reply_secret_msg, - decrypted_reply_as_vec, - Some(tmp_decrypted_msg_id[..HEX_ENCODED_HASH_SIZE].to_vec()), - )) + Ok(ParsedMessage { + should_validate_sig_info: true, + was_msg_encrypted: true, + secret_msg: reply_secret_msg, + decrypted_msg: decrypted_reply_as_vec, + contract_hash_for_validation: Some( + tmp_decrypted_msg_id[..HEX_ENCODED_HASH_SIZE].to_vec(), + ), + }) } SubMsgResult::Err(response) => { let secret_msg = SecretMessage { @@ -511,19 +496,22 @@ pub fn parse_message( msg: serialized_encrypted_reply, }; - Ok(( - ShouldValidateSigInfo::from(true), - WasMessageEncrypted::from(true), - reply_secret_msg, - decrypted_reply_as_vec, - Some(tmp_decrypted_msg_id[..HEX_ENCODED_HASH_SIZE].to_vec()), - )) + Ok(ParsedMessage { + should_validate_sig_info: true, + was_msg_encrypted: true, + secret_msg: reply_secret_msg, + decrypted_msg: decrypted_reply_as_vec, + contract_hash_for_validation: Some( + tmp_decrypted_msg_id[..HEX_ENCODED_HASH_SIZE].to_vec(), + ), + }) } } } }; } +#[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] pub fn handle( context: Ctx, gas_limit: u64, @@ -584,33 +572,33 @@ pub fn handle( // When the message is handle, we expect it always to be encrypted while in Reply for example it might be plaintext let parsed_handle_type = HandleType::try_from(handle_type)?; - let ( + let ParsedMessage { should_validate_sig_info, was_msg_encrypted, secret_msg, decrypted_msg, contract_hash_for_validation, - ) = parse_message(msg, &parsed_sig_info, &parsed_handle_type)?; + } = parse_message(msg, &parsed_sig_info, &parsed_handle_type)?; // There is no signature to verify when the input isn't signed. // Receiving unsigned messages is only possible in Handle. (Init tx are always signed) // All of these functions go through handle but the data isn't signed: // Reply (that is not WASM reply) - if should_validate_sig_info.into() { + if should_validate_sig_info { // Verify env parameters against the signed tx verify_params(&parsed_sig_info, &env_v010, &secret_msg)?; } let mut validated_msg = decrypted_msg.clone(); - let mut reply_params: Option<(Vec, u64)> = None; - if was_msg_encrypted.into() { + let mut reply_params: Option = None; + if was_msg_encrypted { let x = validate_msg( &decrypted_msg, contract_code.hash(), contract_hash_for_validation, )?; - validated_msg = x.0; - reply_params = x.1; + validated_msg = x.validated_msg; + reply_params = x.reply_params; } trace!( @@ -656,8 +644,7 @@ pub fn handle( let output = encrypt_output( output, - secret_msg.nonce, - secret_msg.user_public_key, + &secret_msg, &canonical_contract_address, &env_v010.contract_code_hash, reply_params, @@ -722,7 +709,8 @@ pub fn query( "query input afer decryption: {:?}", String::from_utf8_lossy(&decrypted_msg) ); - let validated_msg = validate_msg(&decrypted_msg, contract_code.hash(), None)?.0; + let ValidatedMessage { validated_msg, .. } = + validate_msg(&decrypted_msg, contract_code.hash(), None)?; let mut engine = start_engine( context, @@ -749,8 +737,7 @@ pub fn query( let output = encrypt_output( output, - secret_msg.nonce, - secret_msg.user_public_key, + &secret_msg, &CanonicalAddr(Binary(Vec::new())), // Not used for queries (can't init a new contract from a query) &"".to_string(), // Not used for queries (can't call a sub-message from a query), None, // Not used for queries (Query response is not replied to the caller), diff --git a/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs b/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs index 3dec8bd74..77c30f2c0 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs @@ -133,12 +133,22 @@ pub fn validate_contract_key( calculated_authentication_id == expected_authentication_id } +pub struct ValidatedMessage { + pub validated_msg: Vec, + pub reply_params: Option, +} + +pub struct ReplyParams { + pub recipient_contract_hash: Vec, + pub sub_msg_id: u64, +} + /// Validate that the message sent to the enclave (after decryption) was actually addressed to this contract. pub fn validate_msg( msg: &[u8], contract_hash: [u8; HASH_SIZE], contract_hash_for_validation: Option>, -) -> Result<(Vec, Option<(Vec, u64)>), EnclaveError> { +) -> Result { if contract_hash_for_validation.is_none() && msg.len() < HEX_ENCODED_HASH_SIZE { warn!("Malformed message - expected contract code hash to be prepended to the msg"); return Err(EnclaveError::ValidationFailure); @@ -182,13 +192,19 @@ pub fn validate_msg( let mut reply_recipient_contract_hash: [u8; HEX_ENCODED_HASH_SIZE] = [0u8; HEX_ENCODED_HASH_SIZE]; reply_recipient_contract_hash.copy_from_slice(&validated_msg[0..HEX_ENCODED_HASH_SIZE]); - return Ok(( - validated_msg[HEX_ENCODED_HASH_SIZE..].to_vec(), - Some((reply_recipient_contract_hash.to_vec(), sub_msg_id)), - )); + return Ok(ValidatedMessage { + validated_msg: validated_msg[HEX_ENCODED_HASH_SIZE..].to_vec(), + reply_params: Some(ReplyParams { + recipient_contract_hash: reply_recipient_contract_hash.to_vec(), + sub_msg_id, + }), + }); } - Ok((validated_msg, None)) + Ok(ValidatedMessage { + validated_msg, + reply_params: None, + }) } /// Verify all the parameters sent to the enclave match up, and were signed by the right account. diff --git a/cosmwasm/enclaves/shared/contract-engine/src/io.rs b/cosmwasm/enclaves/shared/contract-engine/src/io.rs index bc4ac974f..8d691b98b 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/io.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/io.rs @@ -1,3 +1,5 @@ +use crate::contract_validation::ReplyParams; + /// This contains all the user-facing functions. In these functions we will be using /// the consensus_io_exchange_keypair and a user-generated key to create a symmetric key /// that is unique to the user and the enclave @@ -101,7 +103,7 @@ pub fn calc_encryption_key(nonce: &IoNonce, user_public_key: &Ed25519PublicKey) fn encrypt_serializable( key: &AESKey, val: &T, - reply_params: &Option<(Vec, u64)>, + reply_params: &Option, ) -> Result where T: ?Sized + Serialize, @@ -122,12 +124,15 @@ where fn encrypt_preserialized_string( key: &AESKey, val: &str, - reply_params: &Option<(Vec, u64)>, + reply_params: &Option, ) -> Result { let serialized = match reply_params { - Some((reply_recipient_contract_hash, _)) => { + Some(ReplyParams { + recipient_contract_hash, + .. + }) => { let mut ser = vec![]; - ser.extend_from_slice(&reply_recipient_contract_hash); + ser.extend_from_slice(&recipient_contract_hash); ser.extend_from_slice(val.as_bytes()); ser } @@ -152,18 +157,17 @@ fn b64_encode(data: &[u8]) -> String { pub fn encrypt_output( output: Vec, - nonce: IoNonce, - user_public_key: Ed25519PublicKey, + secret_msg: &SecretMessage, contract_addr: &CanonicalAddr, - contract_hash: &String, - reply_params: Option<(Vec, u64)>, + contract_hash: &str, + reply_params: Option, sender_addr: &CanonicalAddr, is_query_output: bool, ) -> Result, EnclaveError> { // When encrypting an output we might encrypt an output that is a reply to a caller contract (Via "Reply" endpoint). // Therefore if reply_recipient_contract_hash is not "None" we append it to any encrypted data besided submessages that are irrelevant for replies. // More info in: https://github.com/CosmWasm/cosmwasm/blob/v1.0.0/packages/std/src/results/submessages.rs#L192-L198 - let encryption_key = calc_encryption_key(&nonce, &user_public_key); + let encryption_key = calc_encryption_key(&secret_msg.nonce, &secret_msg.user_public_key); trace!( "Output before encryption: {:?}", String::from_utf8_lossy(&output) @@ -190,7 +194,7 @@ pub fn encrypt_output( Some(ref r) => { let encrypted_id = Binary::from_base64(&encrypt_preserialized_string( &encryption_key, - &r.1.to_string(), + &r.sub_msg_id.to_string(), &reply_params, )?)?; @@ -215,9 +219,9 @@ pub fn encrypt_output( EnclaveError::FailedToSerialize })?; let tmp_secret_msg = SecretMessage { - nonce, - user_public_key, - msg: reply_as_vec.clone(), + nonce: secret_msg.nonce, + user_public_key: secret_msg.user_public_key, + msg: reply_as_vec, }; Some(Binary::from( @@ -240,7 +244,12 @@ pub fn encrypt_output( } => { for msg in &mut ok.messages { if let cosmwasm_v010_types::types::CosmosMsg::Wasm(wasm_msg) = msg { - encrypt_v010_wasm_msg(wasm_msg, nonce, user_public_key, contract_addr)?; + encrypt_v010_wasm_msg( + wasm_msg, + secret_msg.nonce, + secret_msg.user_public_key, + contract_addr, + )?; } } @@ -263,7 +272,7 @@ pub fn encrypt_output( Some(ref r) => { let encrypted_id = Binary::from_base64(&encrypt_preserialized_string( &encryption_key, - &r.1.to_string(), + &r.sub_msg_id.to_string(), &reply_params, )?)?; @@ -295,8 +304,8 @@ pub fn encrypt_output( EnclaveError::FailedToSerialize })?; let tmp_secret_msg = SecretMessage { - nonce, - user_public_key, + nonce: secret_msg.nonce, + user_public_key: secret_msg.user_public_key, msg: reply_as_vec, }; @@ -320,8 +329,8 @@ pub fn encrypt_output( wasm_msg, &sub_msg.reply_on, sub_msg.id, - nonce, - user_public_key, + secret_msg.nonce, + secret_msg.user_public_key, contract_addr, contract_hash, )?; @@ -361,7 +370,7 @@ pub fn encrypt_output( Some(ref r) => { let encrypted_id = Binary::from_base64(&encrypt_preserialized_string( &encryption_key, - &r.1.to_string(), + &r.sub_msg_id.to_string(), &reply_params, )?)?; @@ -389,9 +398,9 @@ pub fn encrypt_output( EnclaveError::FailedToSerialize })?; let tmp_secret_msg = SecretMessage { - nonce, - user_public_key, - msg: reply_as_vec.clone(), + nonce: secret_msg.nonce, + user_public_key: secret_msg.user_public_key, + msg: reply_as_vec, }; Some(Binary::from( @@ -533,7 +542,7 @@ fn encrypt_v1_wasm_msg( nonce: IoNonce, user_public_key: Ed25519PublicKey, contract_addr: &CanonicalAddr, - reply_recipient_contract_hash: &String, + reply_recipient_contract_hash: &str, ) -> Result<(), EnclaveError> { match wasm_msg { enclave_cosmwasm_v1_types::results::WasmMsg::Execute { diff --git a/x/compute/client/rest/query.go b/x/compute/client/rest/query.go index 89b79e2de..8006f23c2 100644 --- a/x/compute/client/rest/query.go +++ b/x/compute/client/rest/query.go @@ -267,7 +267,7 @@ func queryCodeHashHandlerFn(cliCtx client.Context) http.HandlerFunc { err = json.Unmarshal(res, &codeResp) if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("cannot parse as CodeResponse: %w", err)) + rest.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("cannot parse as CodeResponse: %s", err.Error())) return } diff --git a/x/compute/internal/keeper/keeper.go b/x/compute/internal/keeper/keeper.go index 459dab479..ce990e4fe 100644 --- a/x/compute/internal/keeper/keeper.go +++ b/x/compute/internal/keeper/keeper.go @@ -471,7 +471,7 @@ func (k Keeper) Instantiate(ctx sdk.Context, codeID uint64, creator sdk.AccAddre subMessages, err := V010MsgsToV1SubMsgs(contractAddress.String(), res.Messages) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "couldn't convert v010 messages to v1 messages") + return nil, nil, sdkerrors.Wrap(err, "couldn't convert v0.10 messages to v1 messages") } data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, subMessages, res.Log, []v1wasmTypes.Event{}, res.Data, initMsg, verificationInfo, wasmTypes.CosmosMsgVersionV010) diff --git a/x/compute/internal/keeper/keeper_test.go b/x/compute/internal/keeper/keeper_test.go index e13a51584..d87a78a87 100644 --- a/x/compute/internal/keeper/keeper_test.go +++ b/x/compute/internal/keeper/keeper_test.go @@ -423,7 +423,7 @@ func TestInstantiateWithDeposit(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keeper, codeID, _, _, _, _, _ := setupTest(t, "./testdata/contract.wasm") + ctx, keeper, codeID, _, _, _, _, _ := setupTest(t, "./testdata/contract.wasm", sdk.NewCoins()) deposit := 100 var funds int64 = 0 @@ -443,7 +443,7 @@ func TestInstantiateWithDeposit(t *testing.T) { } // when - addr, _, err := initHelperImpl(t, keeper, ctx, codeID, bob, bobPriv, string(initMsgBz), false, false, defaultGasForTests, wasmCalls, int64(deposit)) + addr, _, err := initHelperImpl(t, keeper, ctx, codeID, bob, bobPriv, string(initMsgBz), false, false, defaultGasForTests, wasmCalls, sdk.NewCoins(sdk.NewInt64Coin("denom", int64(deposit)))) // then if spec.expError { require.Error(t, err) @@ -721,7 +721,7 @@ func TestExecuteWithDeposit(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keeper, codeID, _, _, _, _, _ := setupTest(t, "./testdata/contract.wasm") + ctx, keeper, codeID, _, _, _, _, _ := setupTest(t, "./testdata/contract.wasm", sdk.NewCoins()) deposit := int64(100) var funds int64 = 0 @@ -734,7 +734,7 @@ func TestExecuteWithDeposit(t *testing.T) { initMsgBz, err := json.Marshal(InitMsg{Verifier: bob, Beneficiary: fred}) require.NoError(t, err) - contractAddr, _, err := initHelperImpl(t, keeper, ctx, codeID, bob, bobPriv, string(initMsgBz), true, false, defaultGasForTests, -1, 0) + contractAddr, _, err := initHelperImpl(t, keeper, ctx, codeID, bob, bobPriv, string(initMsgBz), true, false, defaultGasForTests, -1, sdk.NewCoins()) require.Empty(t, err) wasmCalls := int64(-1) diff --git a/x/compute/internal/keeper/param_verification_test.go b/x/compute/internal/keeper/param_verification_test.go index 146b9f3d3..8a3f60988 100644 --- a/x/compute/internal/keeper/param_verification_test.go +++ b/x/compute/internal/keeper/param_verification_test.go @@ -206,7 +206,7 @@ func prepareInitSignedTxMultipleMsgs( func TestMultipleSigners(t *testing.T) { // t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, walletA, privKeyA, walletB, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, walletB, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -284,7 +284,7 @@ func TestMultipleSigners(t *testing.T) { func TestWrongSigner(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, _, walletA, _, walletB, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, _, walletB, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -312,7 +312,7 @@ func TestWrongSigner(t *testing.T) { func TestMultiSig(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` msg := types.NewSecretMsg([]byte(codeHash), []byte(initMsg)) @@ -353,14 +353,14 @@ func TestMultiSig(t *testing.T) { ) // Reset wasm events - ctx, keeper, codeID, codeHash, _, _, _, _ = setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, _, _, _ = setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) } } } func TestMultiSigThreshold(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -405,14 +405,14 @@ func TestMultiSigThreshold(t *testing.T) { ) // Reset wasm events - ctx, keeper, codeID, _, _, _, _, _ = setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, _, _, _, _, _ = setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) } } } func TestMultiSigThresholdNotMet(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -444,7 +444,7 @@ func TestMultiSigThresholdNotMet(t *testing.T) { func TestMultiSigExecute(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, _, walletB, privKeyB := setupTest(t, "./testdata/erc20.wasm") + ctx, keeper, codeID, codeHash, _, _, walletB, privKeyB := setupTest(t, "./testdata/erc20.wasm", sdk.NewCoins()) accounts, multisigAccount := generateMultisigAccount(ctx, keeper, 5, 4) @@ -501,7 +501,7 @@ func TestMultiSigExecute(t *testing.T) { func TestMultiSigCallbacks(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) // init contractAddress, initEvents, error := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, false, defaultGasForTests) @@ -567,7 +567,7 @@ func TestMultiSigCallbacks(t *testing.T) { func TestMultiSigInMultiSig(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) accounts, multisigAccount := generateMultisigAccount(ctx, keeper, 5, 3) multiSigPubKeys := []crypto.PubKey{multisigAccount.public, privKeyA.PubKey(), privKeyB.PubKey()} @@ -672,7 +672,7 @@ func TestMultiSigInMultiSig(t *testing.T) { func TestMultiSigInMultiSigDifferentOrder(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) accounts, multisigAccount := generateMultisigAccount(ctx, keeper, 5, 3) multiSigPubKeys := []crypto.PubKey{multisigAccount.public, privKeyA.PubKey(), privKeyB.PubKey()} @@ -777,7 +777,7 @@ func TestMultiSigInMultiSigDifferentOrder(t *testing.T) { func TestInvalidKeyType(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, _, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) edKey := ed25519.GenPrivKey() edPub := edKey.PubKey() @@ -822,7 +822,7 @@ func TestInvalidKeyType(t *testing.T) { func TestInvalidKeyTypeInMultisig(t *testing.T) { t.SkipNow() // skipping till multisig is fixed - ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, _, privKeyA, _, privKeyB := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) edKey := ed25519.GenPrivKey() edPub := edKey.PubKey() @@ -912,7 +912,7 @@ func TestInvalidKeyTypeInMultisig(t *testing.T) { func TestWrongFundsNoFunds(t *testing.T) { t.SkipNow() - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -937,7 +937,7 @@ func TestWrongFundsNoFunds(t *testing.T) { func TestWrongFundsSomeFunds(t *testing.T) { t.SkipNow() - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -962,7 +962,7 @@ func TestWrongFundsSomeFunds(t *testing.T) { func TestWrongMessage(t *testing.T) { t.SkipNow() - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) initMsg := `{"nop":{}}` @@ -997,7 +997,7 @@ func TestWrongMessage(t *testing.T) { func TestWrongContractAddress(t *testing.T) { t.SkipNow() - ctx, keeper, codeID, codeHash, walletA, privKeyA, walletB, privKeyB := setupTest(t, "./testdata/erc20.wasm") + ctx, keeper, codeID, codeHash, walletA, privKeyA, walletB, privKeyB := setupTest(t, "./testdata/erc20.wasm", sdk.NewCoins()) initMsg := fmt.Sprintf(`{"decimals":10,"initial_balances":[{"address":"%s","amount":"108"},{"address":"%s","amount":"53"}],"name":"ReuvenPersonalRustCoin","symbol":"RPRC"}`, walletA.String(), walletB.String()) diff --git a/x/compute/internal/keeper/secret_contracts_test.go b/x/compute/internal/keeper/secret_contracts_test.go index 0e1a4b198..a35f1c3a2 100644 --- a/x/compute/internal/keeper/secret_contracts_test.go +++ b/x/compute/internal/keeper/secret_contracts_test.go @@ -70,7 +70,7 @@ func testEncrypt(t *testing.T, keeper Keeper, ctx sdk.Context, contractAddress s return queryBz, nil } -func setupTest(t *testing.T, wasmPath string) (sdk.Context, Keeper, uint64, string, sdk.AccAddress, crypto.PrivKey, sdk.AccAddress, crypto.PrivKey) { +func setupTest(t *testing.T, wasmPath string, additionalCoinsInWallets sdk.Coins) (sdk.Context, Keeper, uint64, string, sdk.AccAddress, crypto.PrivKey, sdk.AccAddress, crypto.PrivKey) { encodingConfig := MakeEncodingConfig() var transferPortSource types.ICS20TransferPortSource transferPortSource = MockIBCTransferKeeper{GetPortFn: func(ctx sdk.Context) string { @@ -80,10 +80,8 @@ func setupTest(t *testing.T, wasmPath string) (sdk.Context, Keeper, uint64, stri ctx, keepers := CreateTestInput(t, false, SupportedFeatures, &encoders, nil) accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper - topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - walletA, privKeyA := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, deposit.Add(deposit...)) - walletB, privKeyB := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, topUp) + walletA, privKeyA := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, sdk.NewCoins(sdk.NewInt64Coin("denom", 200000)).Add(additionalCoinsInWallets...)) + walletB, privKeyB := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)).Add(additionalCoinsInWallets...)) wasmCode, err := ioutil.ReadFile(wasmPath) require.NoError(t, err) @@ -401,13 +399,13 @@ func initHelper( codeID uint64, creator sdk.AccAddress, creatorPrivKey crypto.PrivKey, initMsg string, isErrorEncrypted bool, isV1Contract bool, gas uint64, ) (sdk.AccAddress, []ContractEvent, cosmwasm.StdError) { - return initHelperImpl(t, keeper, ctx, codeID, creator, creatorPrivKey, initMsg, isErrorEncrypted, isV1Contract, gas, -1, 0) + return initHelperImpl(t, keeper, ctx, codeID, creator, creatorPrivKey, initMsg, isErrorEncrypted, isV1Contract, gas, -1, sdk.NewCoins()) } func initHelperImpl( t *testing.T, keeper Keeper, ctx sdk.Context, codeID uint64, creator sdk.AccAddress, creatorPrivKey crypto.PrivKey, initMsg string, - isErrorEncrypted bool, isV1Contract bool, gas uint64, wasmCallCount int64, coin int64, + isErrorEncrypted bool, isV1Contract bool, gas uint64, wasmCallCount int64, sentFunds sdk.Coins, ) (sdk.AccAddress, []ContractEvent, cosmwasm.StdError) { hashStr := hex.EncodeToString(keeper.GetCodeInfo(ctx, codeID).CodeHash) @@ -431,9 +429,9 @@ func initHelperImpl( log.NewNopLogger(), ).WithGasMeter(gasMeter) - ctx = PrepareInitSignedTx(t, keeper, ctx, creator, creatorPrivKey, initMsgBz, codeID, sdk.NewCoins(sdk.NewInt64Coin("denom", coin))) + ctx = PrepareInitSignedTx(t, keeper, ctx, creator, creatorPrivKey, initMsgBz, codeID, sentFunds) // make the label a random base64 string, because why not? - contractAddress, _, err := keeper.Instantiate(ctx, codeID, creator /* nil,*/, initMsgBz, base64.RawURLEncoding.EncodeToString(nonce), sdk.NewCoins(sdk.NewInt64Coin("denom", coin)), nil) + contractAddress, _, err := keeper.Instantiate(ctx, codeID, creator /* nil,*/, initMsgBz, base64.RawURLEncoding.EncodeToString(nonce), sentFunds, nil) if wasmCallCount < 0 { // default, just check that at least 1 call happened @@ -457,7 +455,7 @@ func initHelperImpl( func TestCallbackSanity(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init contractAddress, initEvents, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -498,7 +496,7 @@ func TestCallbackSanity(t *testing.T) { } func TestSanity(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm", sdk.NewCoins()) // init initMsg := fmt.Sprintf(`{"decimals":10,"initial_balances":[{"address":"%s","amount":"108"},{"address":"%s","amount":"53"}],"name":"ReuvenPersonalRustCoin","symbol":"RPRC"}`, walletA.String(), walletB.String()) @@ -547,7 +545,7 @@ func TestSanity(t *testing.T) { func TestInitLogs(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -568,7 +566,7 @@ func TestInitLogs(t *testing.T) { func TestEmptyLogKeyValue(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -593,7 +591,7 @@ func TestEmptyLogKeyValue(t *testing.T) { func TestEmptyData(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -609,7 +607,7 @@ func TestEmptyData(t *testing.T) { func TestNoData(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -625,7 +623,7 @@ func TestNoData(t *testing.T) { func TestExecuteIllegalInputError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -645,7 +643,7 @@ func TestExecuteIllegalInputError(t *testing.T) { func TestInitIllegalInputError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) _, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `bad input`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -662,7 +660,7 @@ func TestInitIllegalInputError(t *testing.T) { func TestCallbackFromInitAndCallbackEvents(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init first contract so we'd have someone to callback firstContractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -700,7 +698,7 @@ func TestCallbackFromInitAndCallbackEvents(t *testing.T) { } func TestQueryInputParamError(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm", sdk.NewCoins()) // init initMsg := fmt.Sprintf(`{"decimals":10,"initial_balances":[{"address":"%s","amount":"108"},{"address":"%s","amount":"53"}],"name":"ReuvenPersonalRustCoin","symbol":"RPRC"}`, walletA.String(), walletB.String()) @@ -718,7 +716,7 @@ func TestQueryInputParamError(t *testing.T) { func TestUnicodeData(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -734,7 +732,7 @@ func TestUnicodeData(t *testing.T) { func TestInitContractError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) t.Run("generic_err", func(t *testing.T) { _, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"contract_error":{"error_type":"generic_err"}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -832,7 +830,7 @@ func TestInitContractError(t *testing.T) { func TestExecContractError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -933,7 +931,7 @@ func TestExecContractError(t *testing.T) { func TestQueryContractError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1034,7 +1032,7 @@ func TestQueryContractError(t *testing.T) { func TestInitParamError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) codeHash := "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" msg := fmt.Sprintf(`{"callback":{"contract_addr":"notanaddress", "code_hash":"%s"}}`, codeHash) @@ -1049,7 +1047,7 @@ func TestInitParamError(t *testing.T) { func TestCallbackExecuteParamError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1064,7 +1062,7 @@ func TestCallbackExecuteParamError(t *testing.T) { } func TestQueryInputStructureError(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/erc20.wasm", sdk.NewCoins()) // init initMsg := fmt.Sprintf(`{"decimals":10,"initial_balances":[{"address":"%s","amount":"108"},{"address":"%s","amount":"53"}],"name":"ReuvenPersonalRustCoin","symbol":"RPRC"}`, walletA.String(), walletB.String()) @@ -1082,7 +1080,7 @@ func TestQueryInputStructureError(t *testing.T) { func TestInitNotEncryptedInputError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKey, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKey, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) //ctx = sdk.NewContext( // ctx.MultiStore(), @@ -1107,7 +1105,7 @@ func TestInitNotEncryptedInputError(t *testing.T) { func TestExecuteNotEncryptedInputError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1134,7 +1132,7 @@ func TestExecuteNotEncryptedInputError(t *testing.T) { func TestQueryNotEncryptedInputError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1150,7 +1148,7 @@ func TestQueryNotEncryptedInputError(t *testing.T) { func TestInitNoLogs(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init _, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"no_logs":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1164,7 +1162,7 @@ func TestInitNoLogs(t *testing.T) { func TestExecNoLogs(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1181,7 +1179,7 @@ func TestExecNoLogs(t *testing.T) { func TestExecCallbackToInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init first contract contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1222,7 +1220,7 @@ func TestExecCallbackToInit(t *testing.T) { func TestInitCallbackToInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"callback_to_init":{"code_id":%d, "code_hash":"%s"}}`, codeID, codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1257,7 +1255,7 @@ func TestInitCallbackToInit(t *testing.T) { func TestInitCallbackContractError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1276,7 +1274,7 @@ func TestInitCallbackContractError(t *testing.T) { func TestExecCallbackContractError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1296,7 +1294,7 @@ func TestExecCallbackContractError(t *testing.T) { func TestExecCallbackBadParam(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1323,7 +1321,7 @@ func TestExecCallbackBadParam(t *testing.T) { func TestInitCallbackBadParam(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init first contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1350,7 +1348,7 @@ func TestInitCallbackBadParam(t *testing.T) { func TestState(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // init contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1381,7 +1379,7 @@ func TestState(t *testing.T) { func TestCanonicalizeAddressErrors(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, initEvents, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1398,7 +1396,7 @@ func TestCanonicalizeAddressErrors(t *testing.T) { func TestInitPanic(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) _, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"panic":{}}`, false, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1411,7 +1409,7 @@ func TestInitPanic(t *testing.T) { func TestExecPanic(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1427,7 +1425,7 @@ func TestExecPanic(t *testing.T) { func TestQueryPanic(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1442,7 +1440,7 @@ func TestQueryPanic(t *testing.T) { func TestAllocateOnHeapFailBecauseMemoryLimit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1462,7 +1460,7 @@ func TestAllocateOnHeapFailBecauseMemoryLimit(t *testing.T) { func TestAllocateOnHeapFailBecauseGasLimit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1492,7 +1490,7 @@ func TestAllocateOnHeapFailBecauseGasLimit(t *testing.T) { func TestAllocateOnHeapMoreThanSGXHasFailBecauseMemoryLimit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1514,7 +1512,7 @@ func TestAllocateOnHeapMoreThanSGXHasFailBecauseMemoryLimit(t *testing.T) { func TestPassNullPointerToImports(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1547,7 +1545,7 @@ func TestPassNullPointerToImports(t *testing.T) { func TestExternalQueryWorks(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1563,7 +1561,7 @@ func TestExternalQueryWorks(t *testing.T) { func TestExternalQueryCalleePanic(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1578,7 +1576,7 @@ func TestExternalQueryCalleePanic(t *testing.T) { func TestExternalQueryCalleeStdError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1594,7 +1592,7 @@ func TestExternalQueryCalleeStdError(t *testing.T) { func TestExternalQueryCalleeDoesntExist(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1610,7 +1608,7 @@ func TestExternalQueryCalleeDoesntExist(t *testing.T) { func TestExternalQueryBadSenderABI(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1634,7 +1632,7 @@ func TestExternalQueryBadSenderABI(t *testing.T) { func TestExternalQueryBadReceiverABI(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1657,7 +1655,7 @@ func TestExternalQueryBadReceiverABI(t *testing.T) { func TestMsgSenderInCallback(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1683,7 +1681,7 @@ func TestInfiniteQueryLoopKilledGracefullyByOOM(t *testing.T) { t.SkipNow() // We no longer expect to hit OOM trivially for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1700,7 +1698,7 @@ func TestInfiniteQueryLoopKilledGracefullyByOOM(t *testing.T) { func TestQueryRecursionLimitEnforcedInQueries(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1718,7 +1716,7 @@ func TestQueryRecursionLimitEnforcedInQueries(t *testing.T) { func TestQueryRecursionLimitEnforcedInHandles(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -1736,7 +1734,7 @@ func TestQueryRecursionLimitEnforcedInHandles(t *testing.T) { func TestQueryRecursionLimitEnforcedInInits(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) // Initialize a contract that we will be querying addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -1761,7 +1759,7 @@ func TestQueryRecursionLimitEnforcedInInits(t *testing.T) { func TestWriteToStorageDuringQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1776,7 +1774,7 @@ func TestWriteToStorageDuringQuery(t *testing.T) { func TestRemoveFromStorageDuringQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1791,7 +1789,7 @@ func TestRemoveFromStorageDuringQuery(t *testing.T) { func TestDepositToContract(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1820,7 +1818,7 @@ func TestDepositToContract(t *testing.T) { func TestContractSendFunds(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1850,7 +1848,7 @@ func TestContractSendFunds(t *testing.T) { // In V1 there is no "from" field in Bank message functionality which means it shouldn't be tested func TestContractTryToSendFundsFromSomeoneElse(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, false, defaultGasForTests) require.Empty(t, initErr) @@ -1874,7 +1872,7 @@ func TestContractTryToSendFundsFromSomeoneElse(t *testing.T) { func TestContractSendFundsToInitCallback(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1907,7 +1905,7 @@ func TestContractSendFundsToInitCallback(t *testing.T) { func TestContractSendFundsToInitCallbackNotEnough(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1937,7 +1935,7 @@ func TestContractSendFundsToInitCallbackNotEnough(t *testing.T) { func TestContractSendFundsToExecCallback(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -1971,7 +1969,7 @@ func TestContractSendFundsToExecCallback(t *testing.T) { func TestContractSendFundsToExecCallbackNotEnough(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2006,7 +2004,7 @@ func TestContractSendFundsToExecCallbackNotEnough(t *testing.T) { func TestSleep(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2023,9 +2021,9 @@ func TestSleep(t *testing.T) { func TestGasIsChargedForInitCallbackToInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"callback_to_init":{"code_id":%d,"code_hash":"%s"}}`, codeID, codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"callback_to_init":{"code_id":%d,"code_hash":"%s"}}`, codeID, codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.Empty(t, err) }) } @@ -2034,12 +2032,12 @@ func TestGasIsChargedForInitCallbackToInit(t *testing.T) { func TestGasIsChargedForInitCallbackToExec(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"callback":{"contract_addr":"%s","code_hash":"%s"}}`, addr, codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"callback":{"contract_addr":"%s","code_hash":"%s"}}`, addr, codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.Empty(t, err) }) } @@ -2048,7 +2046,7 @@ func TestGasIsChargedForInitCallbackToExec(t *testing.T) { func TestGasIsChargedForExecCallbackToInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2063,7 +2061,7 @@ func TestGasIsChargedForExecCallbackToInit(t *testing.T) { func TestGasIsChargedForExecCallbackToExec(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2080,7 +2078,7 @@ func TestGasIsChargedForExecExternalQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2096,12 +2094,12 @@ func TestGasIsChargedForInitExternalQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"send_external_query_depth_counter":{"to":"%s","depth":2,"code_hash":"%s"}}`, addr.String(), codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 3, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"send_external_query_depth_counter":{"to":"%s","depth":2,"code_hash":"%s"}}`, addr.String(), codeHash), true, testContract.IsCosmWasmV1, defaultGasForTests, 3, sdk.NewCoins()) require.Empty(t, err) }) } @@ -2112,7 +2110,7 @@ func TestGasIsChargedForQueryExternalQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2124,7 +2122,7 @@ func TestGasIsChargedForQueryExternalQuery(t *testing.T) { } func TestWasmTooHighInitialMemoryRuntimeFail(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/too-high-initial-memory.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/too-high-initial-memory.wasm", sdk.NewCoins()) _, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, false, defaultGasForTests) require.NotNil(t, err.GenericErr) @@ -2154,7 +2152,7 @@ func TestWasmTooHighInitialMemoryStaticFail(t *testing.T) { func TestWasmWithFloatingPoints(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract_with_floats.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/test-contract/contract_with_floats.wasm", sdk.NewCoins()) _, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, testContract.IsCosmWasmV1, defaultGasForTests) require.NotNil(t, err.GenericErr) @@ -2166,7 +2164,7 @@ func TestWasmWithFloatingPoints(t *testing.T) { func TestCodeHashInvalid(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(`AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA{"nop":{}`) enc, _ := wasmCtx.Encrypt(initMsg) @@ -2182,7 +2180,7 @@ func TestCodeHashInvalid(t *testing.T) { func TestCodeHashEmpty(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(`{"nop":{}`) enc, _ := wasmCtx.Encrypt(initMsg) @@ -2198,7 +2196,7 @@ func TestCodeHashEmpty(t *testing.T) { func TestCodeHashNotHex(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(`🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉{"nop":{}}`) enc, _ := wasmCtx.Encrypt(initMsg) @@ -2214,7 +2212,7 @@ func TestCodeHashNotHex(t *testing.T) { func TestCodeHashTooSmall(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(codeHash[0:63] + `{"nop":{}`) @@ -2231,7 +2229,7 @@ func TestCodeHashTooSmall(t *testing.T) { func TestCodeHashTooBig(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(codeHash + "a" + `{"nop":{}`) @@ -2251,7 +2249,7 @@ func TestCodeHashTooBig(t *testing.T) { func TestCodeHashWrong(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privWalletA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) initMsg := []byte(`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855{"nop":{}`) @@ -2268,10 +2266,10 @@ func TestCodeHashWrong(t *testing.T) { func TestCodeHashInitCallInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) t.Run("GoodCodeHash", func(t *testing.T) { - addr, events, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%s","msg":"%s","label":"1"}}`, codeID, codeHash, `{\"nop\":{}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + addr, events, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%s","msg":"%s","label":"1"}}`, codeID, codeHash, `{\"nop\":{}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.Empty(t, err) require.Equal(t, @@ -2289,7 +2287,7 @@ func TestCodeHashInitCallInit(t *testing.T) { ) }) t.Run("EmptyCodeHash", func(t *testing.T) { - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"","msg":"%s","label":"2"}}`, codeID, `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"","msg":"%s","label":"2"}}`, codeID, `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2298,7 +2296,7 @@ func TestCodeHashInitCallInit(t *testing.T) { ) }) t.Run("TooBigCodeHash", func(t *testing.T) { - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%sa","msg":"%s","label":"3"}}`, codeID, codeHash, `{\"nop\":{}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%sa","msg":"%s","label":"3"}}`, codeID, codeHash, `{\"nop\":{}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2307,7 +2305,7 @@ func TestCodeHashInitCallInit(t *testing.T) { ) }) t.Run("TooSmallCodeHash", func(t *testing.T) { - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%s","msg":"%s","label":"4"}}`, codeID, codeHash[0:63], `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"%s","msg":"%s","label":"4"}}`, codeID, codeHash[0:63], `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2316,7 +2314,7 @@ func TestCodeHashInitCallInit(t *testing.T) { ) }) t.Run("IncorrectCodeHash", func(t *testing.T) { - _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","msg":"%s","label":"5"}}`, codeID, `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_init":{"code_id":%d,"code_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","msg":"%s","label":"5"}}`, codeID, `{\"nop\":{}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2331,13 +2329,13 @@ func TestCodeHashInitCallInit(t *testing.T) { func TestCodeHashInitCallExec(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) - addr, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests, 1, 0) + addr, _, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests, 1, sdk.NewCoins()) require.Empty(t, err) t.Run("GoodCodeHash", func(t *testing.T) { - addr2, events, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%s","msg":"%s"}}`, addr.String(), codeHash, `{\"c\":{\"x\":1,\"y\":1}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + addr2, events, err := initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%s","msg":"%s"}}`, addr.String(), codeHash, `{\"c\":{\"x\":1,\"y\":1}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.Empty(t, err) require.Equal(t, @@ -2355,7 +2353,7 @@ func TestCodeHashInitCallExec(t *testing.T) { ) }) t.Run("EmptyCodeHash", func(t *testing.T) { - _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"","msg":"%s"}}`, addr.String(), `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"","msg":"%s"}}`, addr.String(), `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2364,7 +2362,7 @@ func TestCodeHashInitCallExec(t *testing.T) { ) }) t.Run("TooBigCodeHash", func(t *testing.T) { - _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%sa","msg":"%s"}}`, addr.String(), codeHash, `{\"c\":{\"x\":1,\"y\":1}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%sa","msg":"%s"}}`, addr.String(), codeHash, `{\"c\":{\"x\":1,\"y\":1}}`), true, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2373,7 +2371,7 @@ func TestCodeHashInitCallExec(t *testing.T) { ) }) t.Run("TooSmallCodeHash", func(t *testing.T) { - _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%s","msg":"%s"}}`, addr.String(), codeHash[0:63], `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"%s","msg":"%s"}}`, addr.String(), codeHash[0:63], `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2382,7 +2380,7 @@ func TestCodeHashInitCallExec(t *testing.T) { ) }) t.Run("IncorrectCodeHash", func(t *testing.T) { - _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","msg":"%s"}}`, addr.String(), `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, 0) + _, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"call_to_exec":{"addr":"%s","code_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","msg":"%s"}}`, addr.String(), `{\"c\":{\"x\":1,\"y\":1}}`), false, testContract.IsCosmWasmV1, defaultGasForTests, 2, sdk.NewCoins()) require.NotEmpty(t, err) require.Contains(t, @@ -2397,7 +2395,7 @@ func TestCodeHashInitCallExec(t *testing.T) { func TestCodeHashInitCallQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2459,7 +2457,7 @@ func TestCodeHashInitCallQuery(t *testing.T) { func TestCodeHashExecCallInit(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2532,7 +2530,7 @@ func TestCodeHashExecCallInit(t *testing.T) { func TestLabelCollisionWhenMultipleCallbacksToInitFromSameContract(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2551,7 +2549,7 @@ func TestLabelCollisionWhenMultipleCallbacksToInitFromSameContract(t *testing.T) func TestCodeHashExecCallExec(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2624,7 +2622,7 @@ func TestCodeHashExecCallExec(t *testing.T) { func TestQueryGasPrice(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2642,7 +2640,7 @@ func TestQueryGasPrice(t *testing.T) { func TestCodeHashExecCallQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2711,7 +2709,7 @@ func TestCodeHashExecCallQuery(t *testing.T) { func TestCodeHashQueryCallQuery(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, codeHash, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, err) @@ -2770,7 +2768,7 @@ func TestCodeHashQueryCallQuery(t *testing.T) { } func TestEncryptedAndPlaintextLogs(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/plaintext_logs.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/plaintext_logs.wasm", sdk.NewCoins()) addr, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{}`, true, false, defaultGasForTests) require.Empty(t, err) @@ -2794,7 +2792,7 @@ func TestEncryptedAndPlaintextLogs(t *testing.T) { func TestSecp256k1Verify(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -2923,7 +2921,7 @@ func TestBenchmarkSecp256k1VerifyAPI(t *testing.T) { // and not testing.B and I just wanted to quickly get a feel for the perf improvements for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -2942,7 +2940,7 @@ func TestBenchmarkSecp256k1VerifyCrate(t *testing.T) { // and not testing.B and I just wanted to quickly get a feel for the perf improvements for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -2958,7 +2956,7 @@ func TestBenchmarkSecp256k1VerifyCrate(t *testing.T) { func TestEd25519Verify(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -3027,7 +3025,7 @@ func TestEd25519Verify(t *testing.T) { func TestEd25519BatchVerify(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -3180,7 +3178,7 @@ func TestEd25519BatchVerify(t *testing.T) { func TestSecp256k1RecoverPubkey(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -3218,7 +3216,7 @@ func TestSecp256k1RecoverPubkey(t *testing.T) { func TestSecp256k1Sign(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -3253,7 +3251,7 @@ func TestSecp256k1Sign(t *testing.T) { func TestEd25519Sign(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) require.Empty(t, initErr) @@ -3291,7 +3289,7 @@ func TestBenchmarkEd25519BatchVerifyAPI(t *testing.T) { // and not testing.B and I just wanted to quickly get a feel for the performance improvements for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath) + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, testContract.WasmFilePath, sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, testContract.IsCosmWasmV1, defaultGasForTests) @@ -3314,7 +3312,7 @@ type v1QueryResponse struct { } func TestV1EndpointsSanity(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests) @@ -3334,7 +3332,7 @@ func TestV1EndpointsSanity(t *testing.T) { } func TestV1QueryWorksWithEnv(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":0}}`, true, true, defaultGasForTests) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 10) @@ -3350,7 +3348,7 @@ func TestV1QueryWorksWithEnv(t *testing.T) { } func TestV1ReplySanity(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests) @@ -3395,7 +3393,7 @@ func TestV1ReplySanity(t *testing.T) { } func TestV1ReplyLoop(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests) @@ -3405,8 +3403,127 @@ func TestV1ReplyLoop(t *testing.T) { require.Equal(t, uint32(20), binary.BigEndian.Uint32(data)) } +func TestV010BankMsgSendFrom(t *testing.T) { + for _, callType := range []string{"init", "exec"} { + t.Run(callType, func(t *testing.T) { + ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, "./testdata/test-contract/contract.wasm", sdk.NewCoins()) + + var err cosmwasm.StdError + var contractAddress sdk.AccAddress + + if callType == "init" { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, defaultGasForTests, -1, sdk.NewCoins()) + } else { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, false, defaultGasForTests, -1, sdk.NewCoins()) + + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, math.MaxUint64, 0) + } + + require.NotEmpty(t, err) + require.Contains(t, err.Error(), "contract doesn't have permission to send funds from another account") + }) + } +} + +func TestBankMsgSend(t *testing.T) { + for _, contract := range testContracts { + t.Run(contract.CosmWasmVersion, func(t *testing.T) { + for _, callType := range []string{"init", "exec"} { + t.Run(callType, func(t *testing.T) { + for _, test := range []struct { + description string + input string + isSuccuss bool + errorMsg string + balancesBefore string + balancesAfter string + }{ + { + description: "regular", + input: `[{"amount":"2","denom":"denom"}]`, + isSuccuss: true, + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5000assaf,5002denom", + }, + { + description: "multi-coin", + input: `[{"amount":"1","denom":"assaf"},{"amount":"1","denom":"denom"}]`, + isSuccuss: true, + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5001assaf,5001denom", + }, + { + description: "zero", + input: `[{"amount":"0","denom":"denom"}]`, + isSuccuss: false, + errorMsg: "encrypted: dispatch: submessages: 0denom: invalid coins", + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5000assaf,5000denom", + }, + { + description: "insufficient funds", + input: `[{"amount":"3","denom":"denom"}]`, + isSuccuss: false, + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5000assaf,5000denom", + errorMsg: "encrypted: dispatch: submessages: 2denom is smaller than 3denom: insufficient funds", + }, + { + description: "non-existing denom", + input: `[{"amount":"1","denom":"blabla"}]`, + isSuccuss: false, + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5000assaf,5000denom", + errorMsg: "encrypted: dispatch: submessages: 0blabla is smaller than 1blabla: insufficient funds", + }, + { + description: "none", + input: `[]`, + isSuccuss: true, + balancesBefore: "5000assaf,200000denom 5000assaf,5000denom", + balancesAfter: "4998assaf,199998denom 5000assaf,5000denom", + }, + } { + t.Run(test.description, func(t *testing.T) { + ctx, keeper, codeID, _, walletA, privKeyA, walletB, _ := setupTest(t, contract.WasmFilePath, sdk.NewCoins(sdk.NewInt64Coin("assaf", 5000))) + + walletACoinsBefore := keeper.bankKeeper.GetAllBalances(ctx, walletA) + walletBCoinsBefore := keeper.bankKeeper.GetAllBalances(ctx, walletB) + + require.Equal(t, test.balancesBefore, walletACoinsBefore.String()+" "+walletBCoinsBefore.String()) + + var err cosmwasm.StdError + var contractAddress sdk.AccAddress + + if callType == "init" { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins(sdk.NewInt64Coin("denom", 2), sdk.NewInt64Coin("assaf", 2))) + } else { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins(sdk.NewInt64Coin("denom", 2), sdk.NewInt64Coin("assaf", 2))) + + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, math.MaxUint64, 0) + } + + if test.isSuccuss { + require.Empty(t, err) + } else { + require.NotEmpty(t, err) + require.Equal(t, err.Error(), test.errorMsg) + } + + walletACoinsAfter := keeper.bankKeeper.GetAllBalances(ctx, walletA) + walletBCoinsAfter := keeper.bankKeeper.GetAllBalances(ctx, walletB) + + require.Equal(t, test.balancesAfter, walletACoinsAfter.String()+" "+walletBCoinsAfter.String()) + }) + } + }) + } + }) + } +} + func TestV1ReplyOnMultipleSubmessages(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests) @@ -3417,7 +3534,7 @@ func TestV1ReplyOnMultipleSubmessages(t *testing.T) { } func TestV1MultipleSubmessagesNoReply(t *testing.T) { - ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm") + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests) diff --git a/x/compute/internal/keeper/test_common.go b/x/compute/internal/keeper/test_common.go index 9007e7bad..cb9639ac0 100644 --- a/x/compute/internal/keeper/test_common.go +++ b/x/compute/internal/keeper/test_common.go @@ -496,8 +496,7 @@ func PrepareInitSignedTx(t *testing.T, keeper Keeper, ctx sdk.Context, creator s require.NoError(t, err) initMsg := wasmtypes.MsgInstantiateContract{ - Sender: creator, - // Admin: nil, + Sender: creator, CodeID: codeID, Label: "demo contract 1", InitMsg: encMsg, diff --git a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs index a816ecc97..ebb663ad0 100644 --- a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs @@ -73,6 +73,11 @@ pub enum InitMsg { InitFromV1 { counter: u64, }, + BankMsg { + amount: Vec, + to: HumanAddr, + from: Option, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -164,6 +169,11 @@ pub enum HandleMsg { to: HumanAddr, from: HumanAddr, }, + BankMsg { + amount: Vec, + to: HumanAddr, + from: Option, + }, SendFundsToInitCallback { amount: u32, denom: String, @@ -409,6 +419,18 @@ pub fn init( log: vec![], }) } + InitMsg::BankMsg { + to, + amount: coins, + from, + } => Ok(InitResponse { + messages: vec![CosmosMsg::Bank(BankMsg::Send { + from_address: from.unwrap_or(env.contract.address), + to_address: to, + amount: coins, + })], + log: vec![], + }), } } @@ -622,6 +644,15 @@ pub fn handle( log: vec![], data: None, }), + HandleMsg::BankMsg { to, amount, from } => Ok(HandleResponse { + messages: vec![CosmosMsg::Bank(BankMsg::Send { + from_address: from.unwrap_or(env.contract.address), + to_address: to, + amount, + })], + log: vec![], + data: None, + }), HandleMsg::SendFundsToInitCallback { amount, denom, diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract.wasm b/x/compute/internal/keeper/testdata/v1-sanity-contract.wasm deleted file mode 100755 index fb86508ad..000000000 Binary files a/x/compute/internal/keeper/testdata/v1-sanity-contract.wasm and /dev/null differ diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.lock b/x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.lock index 0afe44cf8..b5eb2fefa 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.lock +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.lock @@ -56,7 +56,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" version = "1.0.0" -source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#ae7272784f38fd58a4065d194a91cc9b4f5e5fa7" +source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#4acae6ac8182b7629aa0f58cdab73fcec1305a48" dependencies = [ "digest", "ed25519-zebra", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "cosmwasm-derive" version = "1.0.0" -source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#ae7272784f38fd58a4065d194a91cc9b4f5e5fa7" +source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#4acae6ac8182b7629aa0f58cdab73fcec1305a48" dependencies = [ "syn", ] @@ -76,7 +76,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" version = "1.0.0" -source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#ae7272784f38fd58a4065d194a91cc9b4f5e5fa7" +source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#4acae6ac8182b7629aa0f58cdab73fcec1305a48" dependencies = [ "base64", "cosmwasm-crypto", @@ -92,7 +92,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" version = "1.0.0" -source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#ae7272784f38fd58a4065d194a91cc9b4f5e5fa7" +source = "git+https://github.com/scrtlabs/cosmwasm?branch=secret#4acae6ac8182b7629aa0f58cdab73fcec1305a48" dependencies = [ "cosmwasm-std", "serde", @@ -467,9 +467,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] @@ -494,9 +494,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs index 6e241da55..0acc31b5e 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs @@ -144,6 +144,12 @@ pub fn instantiate( Ok(Response::new().add_attribute("c", format!("{}", answer))) } + InstantiateMsg::BankMsg { to, amount } => { + Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Send { + to_address: to, + amount, + }))) + } } } @@ -534,6 +540,12 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S return res; } + ExecuteMsg::BankMsg { to, amount } => { + Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Send { + to_address: to, + amount, + }))) + } } } diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs index 97e40eb0f..7236fa253 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs @@ -1,8 +1,8 @@ -use cosmwasm_std::Binary; +use cosmwasm_std::{Binary, Coin}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "snake_case")] pub enum InstantiateMsg { Counter { @@ -59,6 +59,10 @@ pub enum InstantiateMsg { code_hash: String, msg: String, }, + BankMsg { + amount: Vec, + to: String, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] @@ -258,6 +262,10 @@ pub enum ExecuteMsg { privkey: Binary, iterations: u32, }, + BankMsg { + amount: Vec, + to: String, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]