Skip to content

Commit

Permalink
Merge pull request #1164 from scrtlabs/test-outputs
Browse files Browse the repository at this point in the history
Test outputs
  • Loading branch information
liorbond authored Sep 11, 2022
2 parents f6d1bf6 + 26c1a07 commit 88eebbc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
4 changes: 0 additions & 4 deletions go-cosmwasm/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contract-v1/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
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(
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions integration-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
fromBase64,
fromUtf8,
MsgExecuteContract,
MsgInstantiateContract,
ProposalType,
SecretNetworkClient,
toBase64,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -455,6 +461,48 @@ describe("Env", () => {
});
});

describe("Init", () => {
test("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]);
expect(resp.address).toBe(logAddr);
expect(resp.data[0]).toBe(137);
});

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]);
expect(resp.data[0]).toBe(137);
});

test("v0.10", async () => {});
});

describe("CustomMsg", () => {
test.skip("v1", async () => {
// TODO
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions x/compute/internal/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 88eebbc

Please sign in to comment.