From 67f8130f12c749570aeea7a7fb326ab6152f6309 Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Sun, 11 Sep 2022 11:32:21 +0300 Subject: [PATCH 1/2] Test init and execute data --- go-cosmwasm/lib.go | 4 -- integration-tests/contract-v1/src/contract.rs | 2 +- integration-tests/package.json | 2 +- integration-tests/test.ts | 48 +++++++++++++++++++ integration-tests/yarn.lock | 8 ++-- x/compute/internal/keeper/msg_dispatcher.go | 4 +- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/go-cosmwasm/lib.go b/go-cosmwasm/lib.go index 197096c7d..546a925c4 100644 --- a/go-cosmwasm/lib.go +++ b/go-cosmwasm/lib.go @@ -186,8 +186,6 @@ func (w *Wasmer) Instantiate( if err != nil { return nil, nil, gasUsed, fmt.Errorf("cannot serialize v0.10 DataWithInternalReplyInfo into binary : %w", err) } - } else { - respV010orV1.V010.Ok.Data = nil } return respV010orV1.V010.Ok, key, gasUsed, nil @@ -210,8 +208,6 @@ func (w *Wasmer) Instantiate( if err != nil { return nil, nil, gasUsed, fmt.Errorf("cannot serialize v1 DataWithInternalReplyInfo into binary: %w", err) } - } else { - respV010orV1.V1.Ok.Data = nil } return respV010orV1.V1.Ok, key, gasUsed, nil diff --git a/integration-tests/contract-v1/src/contract.rs b/integration-tests/contract-v1/src/contract.rs index 358f6e403..858302853 100644 --- a/integration-tests/contract-v1/src/contract.rs +++ b/integration-tests/contract-v1/src/contract.rs @@ -32,7 +32,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: Msg) -> StdResul fn handle_msg(deps: DepsMut, env: Env, _info: MessageInfo, msg: Msg) -> StdResult { match msg { Msg::Nop {} => { - return Ok(Response::new()); + return Ok(Response::new().set_data(vec![137, 137].as_slice())); } Msg::BankMsgSend { to_address, amount } => { return Ok( diff --git a/integration-tests/package.json b/integration-tests/package.json index d56b8ed2a..c5ac579e9 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -11,7 +11,7 @@ "@types/node": "18.7.9", "jest": "28.1.3", "prettier": "2.7.1", - "secretjs": "^1.4.0-alpha.1", + "secretjs": "^1.4.0-alpha.2", "ts-jest": "28.0.8", "ts-node": "10.9.1", "typescript": "4.7.4" diff --git a/integration-tests/test.ts b/integration-tests/test.ts index c8ec9243d..6ecba9777 100644 --- a/integration-tests/test.ts +++ b/integration-tests/test.ts @@ -5,6 +5,7 @@ import { fromBase64, fromUtf8, MsgExecuteContract, + MsgInstantiateContract, ProposalType, SecretNetworkClient, toBase64, @@ -32,6 +33,11 @@ import { cleanBytes, } from "./utils"; +import { + MsgInstantiateContractResponse, + MsgExecuteContractResponse, +} from "secretjs/dist/protobuf_stuff/secret/compute/v1beta1/msg"; + type Account = { address: string; mnemonic: string; @@ -455,6 +461,48 @@ describe("Env", () => { }); }); +describe("Init", () => { + test.only("v1", async () => { + const tx = await accounts[0].secretjs.tx.compute.instantiateContract( + { + sender: accounts[0].address, + codeId: contracts["secretdev-1"].v1.codeId, + codeHash: contracts["secretdev-1"].v1.codeHash, + initMsg: { nop: {} }, + label: `v1-1-${Date.now()}`, + }, + { gasLimit: 300_000 } + ); + + const logAddr = tx.arrayLog.find((x) => x.key === "contract_address").value; + + const resp = MsgInstantiateContractResponse.decode(tx.data[0]); + console.log(JSON.stringify(resp)); + expect(logAddr).toBe(resp.address); + }); + + test("v0.10", async () => {}); +}); + +describe("Execute", () => { + test("v1", async () => { + const tx = await accounts[0].secretjs.tx.compute.executeContract( + { + sender: accounts[0].address, + contractAddress: contracts["secretdev-1"].v1.address, + codeHash: contracts["secretdev-1"].v1.codeHash, + msg: { nop: {} }, + }, + { gasLimit: 300_000 } + ); + + const resp = MsgExecuteContractResponse.decode(tx.data[0]); + console.log(JSON.stringify(resp)); + }); + + test("v0.10", async () => {}); +}); + describe("CustomMsg", () => { test.skip("v1", async () => { // TODO diff --git a/integration-tests/yarn.lock b/integration-tests/yarn.lock index f042bb455..5fdc7adb1 100644 --- a/integration-tests/yarn.lock +++ b/integration-tests/yarn.lock @@ -2376,10 +2376,10 @@ safe-buffer@~5.1.1: resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== -secretjs@^1.4.0-alpha.1: - version "1.4.0-alpha.1" - resolved "https://registry.yarnpkg.com/secretjs/-/secretjs-1.4.0-alpha.1.tgz#270d4664860ee99034c8874fbc8ff732f9836c2a" - integrity sha512-BG1Dh3bMkLoFEP3fnP9MU0iGJY3tI+ftnwKn+lTydngFHEHTPxLQuLcF7K6YWXu8JI0vRwv2adhioir5VJwJvg== +secretjs@^1.4.0-alpha.2: + version "1.4.0-alpha.2" + resolved "https://registry.yarnpkg.com/secretjs/-/secretjs-1.4.0-alpha.2.tgz#cba71a60a0cf59445db217daeee1fda802a165e9" + integrity sha512-uIdbISIELOqCMyg3K9kDJsvfk4hRYR1mVSFv1FJa39bZ3dyer2wgLdL+8ZH9mKqwCaRSK53Juk/rxj/HIyKSHA== dependencies: "@cosmjs/encoding" "0.27.1" "@cosmjs/math" "0.27.1" diff --git a/x/compute/internal/keeper/msg_dispatcher.go b/x/compute/internal/keeper/msg_dispatcher.go index 042cf813c..14e5b287c 100644 --- a/x/compute/internal/keeper/msg_dispatcher.go +++ b/x/compute/internal/keeper/msg_dispatcher.go @@ -232,12 +232,12 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk } // on failure, revert state from sandbox, and ignore events (just skip doing the above) // we only callback if requested. Short-circuit here the cases we don't want to - if (msg.ReplyOn == v1wasmTypes.ReplySuccess || msg.ReplyOn == v1wasmTypes.ReplyNever) && err != nil { + if err != nil && (msg.ReplyOn == v1wasmTypes.ReplySuccess || msg.ReplyOn == v1wasmTypes.ReplyNever) { // Note: this also handles the case of v0.10 submessage for which the execution failed return nil, err } - if msg.ReplyOn == v1wasmTypes.ReplyNever || (msg.ReplyOn == v1wasmTypes.ReplyError && err == nil) { + if msg.ReplyOn == v1wasmTypes.ReplyNever || (err == nil && msg.ReplyOn == v1wasmTypes.ReplyError) { continue } From 26c1a071114cf3d86788eb69b9c29f87fc25e64b Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Sun, 11 Sep 2022 14:29:58 +0300 Subject: [PATCH 2/2] Fix tests --- integration-tests/test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/test.ts b/integration-tests/test.ts index 6ecba9777..2ae06db19 100644 --- a/integration-tests/test.ts +++ b/integration-tests/test.ts @@ -462,7 +462,7 @@ describe("Env", () => { }); describe("Init", () => { - test.only("v1", async () => { + test("v1", async () => { const tx = await accounts[0].secretjs.tx.compute.instantiateContract( { sender: accounts[0].address, @@ -477,8 +477,8 @@ describe("Init", () => { const logAddr = tx.arrayLog.find((x) => x.key === "contract_address").value; const resp = MsgInstantiateContractResponse.decode(tx.data[0]); - console.log(JSON.stringify(resp)); - expect(logAddr).toBe(resp.address); + expect(resp.address).toBe(logAddr); + expect(resp.data[0]).toBe(137); }); test("v0.10", async () => {}); @@ -497,7 +497,7 @@ describe("Execute", () => { ); const resp = MsgExecuteContractResponse.decode(tx.data[0]); - console.log(JSON.stringify(resp)); + expect(resp.data[0]).toBe(137); }); test("v0.10", async () => {});