cosmwasm/test: add integration tests
This commit is contained in:
parent
c22d0c222b
commit
eb42bc48e7
|
@ -64,10 +64,10 @@ unit-test:
|
|||
## Run unit and integration tests
|
||||
test: artifacts test/node_modules LocalTerra unit-test
|
||||
@if pgrep terrad; then echo "Error: terrad already running. Stop it before running tests"; exit 1; fi
|
||||
cd LocalTerra && docker compose up --detach
|
||||
cd LocalTerra && docker-compose up --detach
|
||||
sleep 5
|
||||
cd test && npm run test || (cd ../LocalTerra && docker compose down && exit 1)
|
||||
cd LocalTerra && docker compose down
|
||||
cd test && npm run test || (cd ../LocalTerra && docker-compose down && exit 1)
|
||||
cd LocalTerra && docker-compose down
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
|
|
@ -5,7 +5,11 @@ import {
|
|||
} from "@certusone/wormhole-sdk";
|
||||
import { Bech32, toHex } from "@cosmjs/encoding";
|
||||
import { describe, expect, jest, test } from "@jest/globals";
|
||||
import { Int, MsgExecuteContract } from "@terra-money/terra.js";
|
||||
import {
|
||||
Int,
|
||||
MsgExecuteContract,
|
||||
MsgUpdateContractAdmin,
|
||||
} from "@terra-money/terra.js";
|
||||
import { keccak256 } from "ethers/lib/utils";
|
||||
import {
|
||||
getNativeBalance,
|
||||
|
@ -19,7 +23,7 @@ import {
|
|||
signAndEncodeVaa,
|
||||
TEST_SIGNER_PKS,
|
||||
} from "../helpers/vaa";
|
||||
import { deploy, storeCode } from "../instantiate";
|
||||
import { deploy, deployWithCodeID, storeCode } from "../instantiate";
|
||||
|
||||
setDefaultWasm("node");
|
||||
|
||||
|
@ -38,8 +42,6 @@ const GUARDIAN_ADDRESS = Buffer.from(
|
|||
).toString("base64");
|
||||
const LUNA_ADDRESS =
|
||||
"01" + keccak256(Buffer.from("uluna", "utf-8")).substring(4); // cut off 0x56 (0x prefix - 1 byte)
|
||||
// const INJ_ADDRESS =
|
||||
// "01" + keccak256(Buffer.from("inj", "utf-8")).substring(4); // cut off 0x56 (0x prefix - 1 byte)
|
||||
const MCK_TOKEN_ID =
|
||||
"00" +
|
||||
keccak256(
|
||||
|
@ -53,8 +55,12 @@ const CONSISTENCY_LEVEL = 0;
|
|||
const CHAIN_ID = 18;
|
||||
|
||||
const WASM_WORMHOLE = "../artifacts/wormhole.wasm";
|
||||
const WASM_SHUTDOWN_WORMHOLE =
|
||||
"../artifacts/shutdown_core_bridge_cosmwasm.wasm";
|
||||
const WASM_WRAPPED_ASSET = "../artifacts/cw20_wrapped_2.wasm";
|
||||
const WASM_TOKEN_BRIDGE = "../artifacts/token_bridge_terra_2.wasm";
|
||||
const WASM_SHUTDOWN_TOKEN_BRIDGE =
|
||||
"../artifacts/shutdown_token_bridge_cosmwasm.wasm";
|
||||
const WASM_MOCK_BRIDGE_INTEGRATION =
|
||||
"../artifacts/mock_bridge_integration_2.wasm";
|
||||
const WASM_CW20 = "../artifacts/cw20_base.wasm";
|
||||
|
@ -62,6 +68,29 @@ const WASM_CW20 = "../artifacts/cw20_base.wasm";
|
|||
// global map of contract addresses for all tests
|
||||
const contracts = new Map<string, string>();
|
||||
|
||||
// global map of contract code IDs
|
||||
const code_ids = new Map<string, number>();
|
||||
|
||||
// The below was generated with:
|
||||
// ```worm generate upgrade -g cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0 -c terra2 -a 11 -m Core```
|
||||
const TO_CORE_11_VAA =
|
||||
"01000000000100de73c57650595dc5de301b13d64f0843b9bf4a6ee7c7a8adfc6524cdc5d3e5642ee6fd2745e685a534d2c2f73701843c8f41c74ec78d0edee158f6e274064dea0000000001000000010001000000000000000000000000000000000000000000000000000000000000000400000000002a2e970000000000000000000000000000000000000000000000000000000000436f7265010012000000000000000000000000000000000000000000000000000000000000000b";
|
||||
|
||||
// The below was generated with:
|
||||
// ```worm generate upgrade -g cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0 -c terra2 -a 16 -m Core```
|
||||
const TO_CORE_16_VAA =
|
||||
"01000000000100dbc8e67e8fdc640d3e7a06b75a5127ae70b733505c68000a311c24ecbb7616575519b6e9b52376a9b3f121dd6c97494d2942cae680c6d52eb8b7573636d68f0200000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000453a8f60000000000000000000000000000000000000000000000000000000000436f72650100120000000000000000000000000000000000000000000000000000000000000010";
|
||||
|
||||
// The below was generated with:
|
||||
// ```worm generate upgrade -g cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0 -c terra2 -a 13 -m TokenBridge```
|
||||
const TO_TB_13_VAA =
|
||||
"010000000001004f8c4a920e8b413fbd3ec90fdb22b9ec71470a5a0073c770887cdf94fbedd1ff148d8432977b76d6a79ef828dd3ae9a46a8f99e9cd344264d612c206d5eff2660000000001000000010001000000000000000000000000000000000000000000000000000000000000000400000000058a2ea000000000000000000000000000000000000000000000546f6b656e427269646765020012000000000000000000000000000000000000000000000000000000000000000d";
|
||||
|
||||
// The below was generated with:
|
||||
// ```worm generate upgrade -g cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0 -c terra2 -a 17 -m TokenBridge```
|
||||
const TO_TB_17_VAA =
|
||||
"010000000001004202bfeca22cdff5a24deffee5bcf80574d213f4061b57b3f55bec314c86e37a76f8a05c5aaae3a3f8d7df366d432578c2a9ac64a555f41405f5b66b125d9fef010000000100000001000100000000000000000000000000000000000000000000000000000000000000040000000002746a6300000000000000000000000000000000000000000000546f6b656e4272696467650200120000000000000000000000000000000000000000000000000000000000000011";
|
||||
|
||||
/*
|
||||
Mirror ethereum/test/bridge.js
|
||||
|
||||
|
@ -101,22 +130,21 @@ test("MCK Hashing", () => {
|
|||
expect(MCK_TOKEN_ID).toBe(knownMck);
|
||||
});
|
||||
|
||||
describe("Bridge Tests", () => {
|
||||
test("Deploy Contracts", (done) => {
|
||||
test("Deploy Contracts", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
|
||||
const governanceAddress = Buffer.from(
|
||||
GOVERNANCE_ADDRESS,
|
||||
"hex"
|
||||
).toString("base64");
|
||||
const governanceAddress = Buffer.from(GOVERNANCE_ADDRESS, "hex").toString(
|
||||
"base64"
|
||||
);
|
||||
|
||||
// wormhole
|
||||
const wormhole = await deploy(
|
||||
const wormhole_code = await storeCode(client, wallet, WASM_WORMHOLE); // 11
|
||||
console.log("wormholeCode:", wormhole_code);
|
||||
const wormhole = await deployWithCodeID(
|
||||
client,
|
||||
wallet,
|
||||
WASM_WORMHOLE,
|
||||
{
|
||||
gov_chain: GOVERNANCE_CHAIN,
|
||||
gov_address: governanceAddress,
|
||||
|
@ -130,9 +158,10 @@ describe("Bridge Tests", () => {
|
|||
expiration_time: 0,
|
||||
},
|
||||
chain_id: 18,
|
||||
fee_denom: "uluna"
|
||||
fee_denom: "uluna",
|
||||
},
|
||||
"wormhole"
|
||||
"wormhole",
|
||||
wormhole_code
|
||||
);
|
||||
console.log("wormhole deployed at", wormhole);
|
||||
// token bridge
|
||||
|
@ -141,10 +170,15 @@ describe("Bridge Tests", () => {
|
|||
wallet,
|
||||
WASM_WRAPPED_ASSET
|
||||
);
|
||||
const tokenBridge = await deploy(
|
||||
const tokenBridge_code = await storeCode(
|
||||
client,
|
||||
wallet,
|
||||
WASM_TOKEN_BRIDGE
|
||||
);
|
||||
console.log("TB codeID:", tokenBridge_code); // 13
|
||||
const tokenBridge = await deployWithCodeID(
|
||||
client,
|
||||
wallet,
|
||||
WASM_TOKEN_BRIDGE,
|
||||
{
|
||||
gov_chain: GOVERNANCE_CHAIN,
|
||||
gov_address: governanceAddress,
|
||||
|
@ -152,7 +186,8 @@ describe("Bridge Tests", () => {
|
|||
wrapped_asset_code_id: wrappedAssetCodeId,
|
||||
chain_id: 18,
|
||||
},
|
||||
"tokenBridge"
|
||||
"tokenBridge",
|
||||
tokenBridge_code
|
||||
);
|
||||
console.log("tokenBridge deployed at", tokenBridge);
|
||||
// mock bridge integration
|
||||
|
@ -186,106 +221,188 @@ describe("Bridge Tests", () => {
|
|||
"mock"
|
||||
);
|
||||
console.log("cw20 deployed at", cw20);
|
||||
|
||||
// Only need the code IDs for the shutdown contracts because
|
||||
// we will only be upgrading the existing contracts.
|
||||
|
||||
// wormhole shutdown contract
|
||||
const wormhole_shutdown_code = await storeCode(
|
||||
client,
|
||||
wallet,
|
||||
WASM_SHUTDOWN_WORMHOLE
|
||||
); //
|
||||
console.log("shutdown wormholeCode:", wormhole_shutdown_code); // 16
|
||||
|
||||
// token bridge shutdown contract
|
||||
const tokenBridge_shutdown_code = await storeCode(
|
||||
client,
|
||||
wallet,
|
||||
WASM_SHUTDOWN_TOKEN_BRIDGE
|
||||
);
|
||||
console.log("shutdown TB codeID:", tokenBridge_shutdown_code); // 17
|
||||
|
||||
console.log("tokenBridge deployed at", tokenBridge);
|
||||
contracts.set("wormhole", wormhole);
|
||||
contracts.set("tokenBridge", tokenBridge);
|
||||
contracts.set("mockBridgeIntegration", mockBridgeIntegration);
|
||||
contracts.set("cw20", cw20);
|
||||
code_ids.set("wormhole", wormhole_code);
|
||||
code_ids.set("tokenBridge", tokenBridge_code);
|
||||
code_ids.set("wrappedAsset", wrappedAssetCodeId);
|
||||
code_ids.set("wormhole_shutdown", wormhole_shutdown_code);
|
||||
code_ids.set("tokenBridge_shutdown", tokenBridge_shutdown_code);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Deploy Contracts");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Query GuardianSetInfo", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client] = await makeProviderAndWallet();
|
||||
});
|
||||
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const result: any = await client.wasm.contractQuery(wormhole, {
|
||||
guardian_set_info: {},
|
||||
});
|
||||
expect(result.guardian_set_index).toBe(0);
|
||||
expect(result.addresses.length).toBe(1);
|
||||
expect(result.addresses[0].bytes).toBe(GUARDIAN_ADDRESS);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Query GuardianSetInfo");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Query State", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client] = await makeProviderAndWallet();
|
||||
alwaysPassTests(false, 1);
|
||||
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const result: any = await client.wasm.contractQuery(wormhole, {
|
||||
get_state: {},
|
||||
});
|
||||
expect(result.fee.amount).toBe("0");
|
||||
expect(result.fee.denom).toBe("uluna");
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Query State");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Post a Message", (done) => {
|
||||
describe("Upgrade to shutdown contracts Tests", () => {
|
||||
test("Set admin of contracts to themselves", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const postMessage = new MsgExecuteContract(
|
||||
try {
|
||||
const corebridge = contracts.get("wormhole")!;
|
||||
await wallet
|
||||
.createAndSignTx({
|
||||
msgs: [
|
||||
new MsgUpdateContractAdmin(
|
||||
wallet.key.accAddress,
|
||||
wormhole,
|
||||
{
|
||||
post_message: {
|
||||
message: Buffer.from("0001020304050607", "hex").toString(
|
||||
"base64"
|
||||
corebridge,
|
||||
corebridge
|
||||
),
|
||||
nonce: 69,
|
||||
],
|
||||
memo: "",
|
||||
})
|
||||
.then((tx) => client.tx.broadcast(tx))
|
||||
.then((rs) => console.log(rs));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to set admin of core bridge to itself");
|
||||
}
|
||||
try {
|
||||
const tokenbridge = contracts.get("tokenBridge")!;
|
||||
await wallet
|
||||
.createAndSignTx({
|
||||
msgs: [
|
||||
new MsgUpdateContractAdmin(
|
||||
wallet.key.accAddress,
|
||||
tokenbridge,
|
||||
tokenbridge
|
||||
),
|
||||
],
|
||||
memo: "",
|
||||
})
|
||||
.then((tx) => client.tx.broadcast(tx))
|
||||
.then((rs) => console.log(rs));
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to set admin of token bridge to itself");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Upgrade to shutdown contracts", (done) => {
|
||||
(async () => {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
try {
|
||||
const corebridge = contracts.get("wormhole")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
corebridge,
|
||||
{
|
||||
submit_v_a_a: {
|
||||
vaa: Buffer.from(TO_CORE_16_VAA, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
postMessage,
|
||||
]);
|
||||
const seq0 = parseSequenceFromLogTerra(receipt as any);
|
||||
expect(seq0).toBe("0");
|
||||
const receipt2 = await transactWithoutMemo(client, wallet, [
|
||||
postMessage,
|
||||
]);
|
||||
const seq1 = parseSequenceFromLogTerra(receipt2 as any);
|
||||
expect(seq1).toBe("1");
|
||||
done();
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Post a Message");
|
||||
done("Failed to upgrade core bridge to shutdown");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Query Token", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client] = await makeProviderAndWallet();
|
||||
|
||||
const cw20 = contracts.get("cw20")!;
|
||||
const result: any = await client.wasm.contractQuery(cw20, {
|
||||
token_info: {},
|
||||
});
|
||||
console.log(result);
|
||||
const tokenbridge = contracts.get("tokenBridge")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
tokenbridge,
|
||||
{
|
||||
submit_vaa: {
|
||||
data: Buffer.from(TO_TB_17_VAA, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Query Token");
|
||||
done("Failed to upgrade token bridge to shutdown");
|
||||
}
|
||||
})();
|
||||
});
|
||||
});
|
||||
|
||||
alwaysPassTests(true, 2);
|
||||
passOnceTests(true, 1);
|
||||
failInShutdownModeTests(true, 1);
|
||||
|
||||
describe("Upgrade to previous non-shutdown contracts Tests", () => {
|
||||
test("Upgrade to normal contracts", (done) => {
|
||||
(async () => {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
try {
|
||||
const corebridge = contracts.get("wormhole")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
corebridge,
|
||||
{
|
||||
submit_v_a_a: {
|
||||
vaa: Buffer.from(TO_CORE_11_VAA, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to upgrade core bridge to normal mode");
|
||||
}
|
||||
try {
|
||||
const tokenbridge = contracts.get("tokenBridge")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
tokenbridge,
|
||||
{
|
||||
submit_vaa: {
|
||||
data: Buffer.from(TO_TB_13_VAA, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to upgrade token bridge to normal mode");
|
||||
}
|
||||
})();
|
||||
});
|
||||
});
|
||||
|
||||
alwaysPassTests(false, 3);
|
||||
passOnceTests(false, 2);
|
||||
failInShutdownModeTests(false, 2);
|
||||
|
||||
function passOnceTests(shutdownMode: boolean, pass: number) {
|
||||
const name: string =
|
||||
"Pass Once Tests for " +
|
||||
(shutdownMode ? "shutdown" : "non-shutdown") +
|
||||
" contracts (pass " +
|
||||
pass.toString() +
|
||||
")";
|
||||
describe(name, () => {
|
||||
test("Register a Foreign Bridge Implementation", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
|
@ -324,11 +441,165 @@ describe("Bridge Tests", () => {
|
|||
}
|
||||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
if (pass > 1) {
|
||||
console.error(
|
||||
"Register a Foreign Bridge Implementation should have failed. VAA already executed."
|
||||
);
|
||||
done(
|
||||
"Register a Foreign Bridge Implementation should have failed. VAA already executed."
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (pass === 1) {
|
||||
console.error(e);
|
||||
done("Failed to Register a Foreign Bridge Implementation");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function failInShutdownModeTests(shutdownMode: boolean, pass: number) {
|
||||
const name: string =
|
||||
"Shutdown mode Tests for " +
|
||||
(shutdownMode ? "shutdown" : "non-shutdown") +
|
||||
" contracts (pass " +
|
||||
pass.toString() +
|
||||
")";
|
||||
describe(name, () => {
|
||||
test("Post a Message", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const postMessage = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
wormhole,
|
||||
{
|
||||
post_message: {
|
||||
message: Buffer.from("0001020304050607", "hex").toString(
|
||||
"base64"
|
||||
),
|
||||
nonce: 69,
|
||||
},
|
||||
}
|
||||
);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
postMessage,
|
||||
]);
|
||||
const seq0 = parseSequenceFromLogTerra(receipt as any);
|
||||
expect(seq0).toBe("0");
|
||||
const receipt2 = await transactWithoutMemo(client, wallet, [
|
||||
postMessage,
|
||||
]);
|
||||
const seq1 = parseSequenceFromLogTerra(receipt2 as any);
|
||||
expect(seq1).toBe("1");
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Post a Message should have failed in shutdown mode."
|
||||
);
|
||||
done("Post a Message should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Post a Message");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Register a Foreign Asset", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
|
||||
const signedVaa =
|
||||
"01000000000100efccb8a5d54162691095c88369b873d93ed4ba9365ed0f94adcf39743bb034be56ce0a94d9b163cb0c63be24b94e31b75e1a5889e3de03db147278d9d3eb7d260100000992abb6000000020000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16000000000000000d0f020000000000000000000000002d8be6bf0baa74e0a907016679cae9190e80dd0a000212544b4e0000000000000000000000000000000000000000000000000000000000457468657265756d205465737420546f6b656e00000000000000000000000000";
|
||||
|
||||
const tokenBridge = contracts.get("tokenBridge")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
tokenBridge,
|
||||
{
|
||||
submit_vaa: {
|
||||
data: Buffer.from(signedVaa, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
console.log(receipt);
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Register a Foreign Asset should have failed in shutdown mode."
|
||||
);
|
||||
done("Register a Foreign Asset should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Register a Foreign Asset");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Update a Foreign Asset", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
|
||||
const signedVaa =
|
||||
"01000000000100d1389731568d9816267accba90abb9db37dcd09738750fae421067f2f7f33f014c2d862e288e9a3149e2d8bcd2e53ffe2ed72dfc5e8eb50c740a0df34c60103f01000011ac2076010000020000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16000000000000000e0f020000000000000000000000002d8be6bf0baa74e0a907016679cae9190e80dd0a000212544b4e0000000000000000000000000000000000000000000000000000000000457468657265756d205465737420546f6b656e00000000000000000000000000";
|
||||
|
||||
const tokenBridge = contracts.get("tokenBridge")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
tokenBridge,
|
||||
{
|
||||
submit_vaa: {
|
||||
data: Buffer.from(signedVaa, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
console.log(receipt);
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Update a Foreign Asset should have failed in shutdown mode."
|
||||
);
|
||||
done("Update a Foreign Asset should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Update a Foreign Asset");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -394,13 +665,29 @@ describe("Bridge Tests", () => {
|
|||
initiateTransfer,
|
||||
]);
|
||||
|
||||
const balanceAfter = await getNativeBalance(client, tokenBridge, denom);
|
||||
const balanceAfter = await getNativeBalance(
|
||||
client,
|
||||
tokenBridge,
|
||||
denom
|
||||
);
|
||||
expect(balanceBefore.add(amount).eq(balanceAfter)).toBeTruthy();
|
||||
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Initiate Transfer (native denom) should have failed in shutdown mode."
|
||||
);
|
||||
done(
|
||||
"Initiate Transfer (native denom) should have failed in shutdown"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Initiate Transfer (native denom)");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -469,7 +756,9 @@ describe("Bridge Tests", () => {
|
|||
});
|
||||
|
||||
// execute outbound transfer with signed vaa
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
|
||||
// check wallet (relayer) balance change
|
||||
const walletBalanceAfter = await getNativeBalance(
|
||||
|
@ -513,11 +802,23 @@ describe("Bridge Tests", () => {
|
|||
expect(
|
||||
bridgeBalanceBefore.sub(bridgeExpectedChange).eq(bridgeBalanceAfter)
|
||||
).toBeTruthy();
|
||||
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Complete Transfer (native denom) should have failed in shutdown mode."
|
||||
);
|
||||
done(
|
||||
"Complete Transfer (native denom) should have failed in shutdown"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Complete Transfer (native denom)");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -641,13 +942,29 @@ describe("Bridge Tests", () => {
|
|||
Buffer.from(myPayload, "ascii").toString("hex")
|
||||
);
|
||||
|
||||
const balanceAfter = await getNativeBalance(client, tokenBridge, denom);
|
||||
const balanceAfter = await getNativeBalance(
|
||||
client,
|
||||
tokenBridge,
|
||||
denom
|
||||
);
|
||||
expect(balanceBefore.add(amount).eq(balanceAfter)).toBeTruthy();
|
||||
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Initiate Transfer With Payload (native denom) should have failed in shutdown mode."
|
||||
);
|
||||
done(
|
||||
"Initiate Transfer With Payload (native denom) should have failed in shutdown"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Initiate Transfer With Payload (native denom)");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -717,7 +1034,9 @@ describe("Bridge Tests", () => {
|
|||
);
|
||||
|
||||
// execute outbound transfer with signed vaa
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
|
||||
// check contract balance change
|
||||
const contractBalanceAfter = await getNativeBalance(
|
||||
|
@ -755,11 +1074,23 @@ describe("Bridge Tests", () => {
|
|||
expect(
|
||||
Buffer.from(transferPayloadResponse.value, "base64").toString()
|
||||
).toEqual(additionalPayload);
|
||||
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Complete Transfer With Payload (native denom) should have failed in shutdown mode."
|
||||
);
|
||||
done(
|
||||
"Complete Transfer With Payload (native denom) should have failed in shutdown"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Complete Transfer With Payload (native denom)");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -808,12 +1139,16 @@ describe("Bridge Tests", () => {
|
|||
|
||||
let expectedErrorFound = false;
|
||||
try {
|
||||
const submitVaa = new MsgExecuteContract(walletAddress, tokenBridge, {
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
walletAddress,
|
||||
tokenBridge,
|
||||
{
|
||||
complete_transfer_with_payload: {
|
||||
data: Buffer.from(signedVaa, "hex").toString("base64"),
|
||||
relayer: walletAddress,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// execute outbound transfer with signed vaa
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
|
@ -827,13 +1162,25 @@ describe("Bridge Tests", () => {
|
|||
}
|
||||
|
||||
expect(expectedErrorFound).toBeTruthy();
|
||||
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Throw on Complete Transfer With Payload If Someone Else Redeems VAA should have failed in shutdown mode."
|
||||
);
|
||||
done(
|
||||
"Throw on Complete Transfer With Payload If Someone Else Redeems VAA should have failed in shutdown"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done(
|
||||
"Failed to Throw on Complete Transfer With Payload If Someone Else Redeems VAA"
|
||||
);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -857,10 +1204,21 @@ describe("Bridge Tests", () => {
|
|||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [attest]);
|
||||
if (shutdownMode) {
|
||||
console.error(
|
||||
"Attest a Native Asset should have failed in shutdown mode."
|
||||
);
|
||||
done("Attest a Native Asset should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Attest a Native Asset");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
@ -887,13 +1245,26 @@ describe("Bridge Tests", () => {
|
|||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [attest]);
|
||||
console.log(receipt);
|
||||
if (shutdownMode) {
|
||||
console.error("Attest a CW20 should have failed in shutdown mode.");
|
||||
done("Attest a CW20 should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode) {
|
||||
console.error(e);
|
||||
done("Failed to Attest a CW20");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
//
|
||||
// This is the only test the gets rejected in shutdown mode (attestations are not allowed)
|
||||
// and if it is run more than once (VAA already executed).
|
||||
//
|
||||
test("Register a Foreign Asset", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
|
@ -913,44 +1284,95 @@ describe("Bridge Tests", () => {
|
|||
}
|
||||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
const receipt = await transactWithoutMemo(client, wallet, [
|
||||
submitVaa,
|
||||
]);
|
||||
console.log(receipt);
|
||||
if (shutdownMode || pass > 1) {
|
||||
console.error(
|
||||
"Register a Foreign asset should have failed in shutdown mode."
|
||||
);
|
||||
done("Register a Foreign asset should have failed in shutdown");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!shutdownMode && pass === 1) {
|
||||
console.error(e);
|
||||
done("Failed to Register a Foreign Asset");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Update a Foreign Asset", (done) => {
|
||||
});
|
||||
}
|
||||
|
||||
function alwaysPassTests(shutdownMode: boolean, pass: number) {
|
||||
const name: string =
|
||||
"Bridge Tests for " +
|
||||
(shutdownMode ? "shutdown" : "non-shutdown") +
|
||||
" contracts (pass " +
|
||||
pass.toString() +
|
||||
")";
|
||||
describe(name, () => {
|
||||
test("Query GuardianSetInfo", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client, wallet] = await makeProviderAndWallet();
|
||||
const [client] = await makeProviderAndWallet();
|
||||
|
||||
const signedVaa =
|
||||
"01000000000100d1389731568d9816267accba90abb9db37dcd09738750fae421067f2f7f33f014c2d862e288e9a3149e2d8bcd2e53ffe2ed72dfc5e8eb50c740a0df34c60103f01000011ac2076010000020000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16000000000000000e0f020000000000000000000000002d8be6bf0baa74e0a907016679cae9190e80dd0a000212544b4e0000000000000000000000000000000000000000000000000000000000457468657265756d205465737420546f6b656e00000000000000000000000000";
|
||||
|
||||
const tokenBridge = contracts.get("tokenBridge")!;
|
||||
const submitVaa = new MsgExecuteContract(
|
||||
wallet.key.accAddress,
|
||||
tokenBridge,
|
||||
{
|
||||
submit_vaa: {
|
||||
data: Buffer.from(signedVaa, "hex").toString("base64"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const receipt = await transactWithoutMemo(client, wallet, [submitVaa]);
|
||||
console.log(receipt);
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const result: any = await client.wasm.contractQuery(wormhole, {
|
||||
guardian_set_info: {},
|
||||
});
|
||||
expect(result.guardian_set_index).toBe(0);
|
||||
expect(result.addresses.length).toBe(1);
|
||||
expect(result.addresses[0].bytes).toBe(GUARDIAN_ADDRESS);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Update a Foreign Asset");
|
||||
done("Failed to Query GuardianSetInfo");
|
||||
}
|
||||
})();
|
||||
});
|
||||
});
|
||||
test("Query State", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client] = await makeProviderAndWallet();
|
||||
|
||||
const wormhole = contracts.get("wormhole")!;
|
||||
const result: any = await client.wasm.contractQuery(wormhole, {
|
||||
get_state: {},
|
||||
});
|
||||
expect(result.fee.amount).toBe("0");
|
||||
expect(result.fee.denom).toBe("uluna");
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Query State");
|
||||
}
|
||||
})();
|
||||
});
|
||||
test("Query Token", (done) => {
|
||||
(async () => {
|
||||
try {
|
||||
const [client] = await makeProviderAndWallet();
|
||||
|
||||
const cw20 = contracts.get("cw20")!;
|
||||
const result: any = await client.wasm.contractQuery(cw20, {
|
||||
token_info: {},
|
||||
});
|
||||
console.log(result);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
done("Failed to Query Token");
|
||||
}
|
||||
})();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function nativeToHex(address: string) {
|
||||
return toHex(Bech32.decode(address).data).padStart(64, "0");
|
||||
|
|
|
@ -49,3 +49,26 @@ export async function deploy(
|
|||
// @ts-ignore
|
||||
return /"_contract_address","value":"([^"]+)/gm.exec(receipt.raw_log)[1];
|
||||
}
|
||||
|
||||
export async function deployWithCodeID(
|
||||
terra: LCDClient,
|
||||
wallet: Wallet,
|
||||
instantiateMsg: Object,
|
||||
label: string,
|
||||
codeId: number
|
||||
): Promise<string> {
|
||||
const msgs = [
|
||||
new MsgInstantiateContract(
|
||||
wallet.key.accAddress,
|
||||
wallet.key.accAddress,
|
||||
codeId,
|
||||
instantiateMsg,
|
||||
undefined,
|
||||
label
|
||||
),
|
||||
];
|
||||
const receipt = await transactWithoutMemo(terra, wallet, msgs);
|
||||
|
||||
// @ts-ignore
|
||||
return /"_contract_address","value":"([^"]+)/gm.exec(receipt.raw_log)[1];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue