Skip to content

Commit d910c6f

Browse files
committed
test sending memo field from secretdev-1 to secretdev-2
1 parent 5c4a8d9 commit d910c6f

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

Diff for: contracts/cw20-ics20/test/docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
# faucet
1414
- "5000:5000"
1515
environment:
16+
FAST_BLOCKS: "true"
1617
LOG_LEVEL: "TRACE"
1718
localsecret-2:
1819
image: "ghcr.io/scrtlabs/localsecret:v1.14.0"
@@ -27,5 +28,6 @@ services:
2728
# faucet
2829
- "5300:5000"
2930
environment:
31+
FAST_BLOCKS: "true"
3032
CHAINID: "secretdev-2"
3133
LOG_LEVEL: "TRACE"

Diff for: contracts/cw20-ics20/test/test.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ let channelId1 = "";
5656
let channelId2 = "";
5757

5858
beforeAll(async () => {
59-
const linkPromise = createIbcConnection();
59+
const link = await createIbcConnection();
60+
61+
await sleep(300)
6062

6163
const mnemonics = [
6264
"grant rice replace explain federal release fix clever romance raise often wild taxi quarter soccer fiber love must tape steak together observe swap guitar",
@@ -93,7 +95,7 @@ beforeAll(async () => {
9395
walletAmino,
9496
walletProto,
9597
secretjs: new SecretNetworkClient({
96-
url: "http://localhost:3317",
98+
url: "http://localhost:2317",
9799
wallet: walletProto,
98100
walletAddress: walletProto.address,
99101
chainId: "secretdev-2",
@@ -102,7 +104,7 @@ beforeAll(async () => {
102104
}
103105

104106
await waitForBlocks("secretdev-1", "http://localhost:1317");
105-
await waitForBlocks("secretdev-2", "http://localhost:3317");
107+
await waitForBlocks("secretdev-2", "http://localhost:2317");
106108

107109
contracts.snip20.wasm = fs.readFileSync(`${__dirname}/snip20.wasm`) as Uint8Array;
108110
contracts.ics20.wasm = fs.readFileSync(`${__dirname}/../contract.wasm`) as Uint8Array;
@@ -129,13 +131,17 @@ beforeAll(async () => {
129131
],
130132
{ gasLimit: 5_000_000 }
131133
);
134+
await sleep(1000);
132135
if (tx.code !== TxResultCode.Success) {
133136
console.error(tx.rawLog);
134137
}
135138
expect(tx.code).toBe(TxResultCode.Success);
136139

140+
137141
contracts.snip20.codeId = Number(tx.arrayLog.find((x) => x.key === "code_id").value);
142+
await sleep(1000);
138143
contracts.ics20.codeId = Number(tx.arrayLog.reverse().find((x) => x.key === "code_id").value);
144+
await sleep(1000);
139145

140146
console.log("Instantiating snip20 on secretdev-1...");
141147

@@ -165,6 +171,8 @@ beforeAll(async () => {
165171
{ gasLimit: 300_000 }
166172
);
167173

174+
await sleep(1000);
175+
168176
contracts.snip20.address = MsgInstantiateContractResponse.decode(tx.data[0]).address;
169177
contracts.snip20.ibcPortId = "wasm." + contracts.snip20.address;
170178

@@ -196,8 +204,12 @@ beforeAll(async () => {
196204
contracts.ics20.address = MsgInstantiateContractResponse.decode(tx.data[0]).address;
197205
contracts.ics20.ibcPortId = "wasm." + contracts.ics20.address;
198206

207+
await sleep(1000);
208+
199209
console.log("Waiting for IBC connection...");
200-
const link = await linkPromise;
210+
// const link = await createIbcConnection();
211+
212+
await sleep(1000);
201213

202214
console.log("Creating IBC channel...");
203215
const channels = await createIbcChannel(link, contracts.ics20.ibcPortId);
@@ -215,6 +227,7 @@ test(
215227
// register snip20 on ics20, then send tokens from secretdev-1
216228
console.log("Sending tokens from secretdev-1...");
217229

230+
const memo1 = "test memo from secretdev-1";
218231
let tx = await accounts1[0].secretjs.tx.broadcast(
219232
[
220233
new MsgExecuteContract({
@@ -245,7 +258,9 @@ test(
245258
})
246259
)
247260
),
261+
memo: memo1,
248262
},
263+
// memo: "test2 memo from secretdev-1",
249264
},
250265
}),
251266
],
@@ -258,6 +273,10 @@ test(
258273
}
259274
expect(tx.code).toBe(TxResultCode.Success);
260275

276+
let res = tx.arrayLog.find(element => element.key === 'memo');
277+
let receivedMemo = res ? res.value : undefined;
278+
expect(receivedMemo).toBe(memo1);
279+
261280
let snip20Balance: any = await accounts1[0].secretjs.query.compute.queryContract({
262281
contract_address: contracts.snip20.address,
263282
code_hash: contracts.snip20.code_hash,
@@ -304,7 +323,7 @@ test(
304323
},
305324
receiver: accounts1[0].address,
306325
timeout_timestamp: String(Math.floor(Date.now() / 1000) + 10 * 60) /* 10 minutes */,
307-
memo: "memo"
326+
memo: "test memo from secretdev-2"
308327
});
309328

310329
if (tx.code !== TxResultCode.Success) {

Diff for: contracts/cw20-ics20/test/utils.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { IbcClient, Link } from "@confio/relayer";
22
import { ChannelPair } from "@confio/relayer/build/lib/link";
3+
import { stringToPath } from "@cosmjs/crypto";
4+
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
35
import { GasPrice } from "@cosmjs/stargate";
46
import { sha256 } from "@noble/hashes/sha256";
57
import { SecretNetworkClient, toHex, toUtf8, Wallet } from "secretjs";
@@ -106,47 +108,53 @@ export async function waitForIBCChannel(chainId: string, url: string, channelId:
106108
export async function createIbcConnection(): Promise<Link> {
107109
// Create signers as LocalSecret account d
108110
// (Both sides are localsecret so same account can be used on both sides)
109-
const signerA = new Wallet(
110-
"word twist toast cloth movie predict advance crumble escape whale sail such angry muffin balcony keen move employ cook valve hurt glimpse breeze brick"
111+
const signerA = await DirectSecp256k1HdWallet.fromMnemonic(
112+
"word twist toast cloth movie predict advance crumble escape whale sail such angry muffin balcony keen move employ cook valve hurt glimpse breeze brick", // account d
113+
{ hdPaths: [stringToPath("m/44'/529'/0'/0/0")], prefix: "secret" },
111114
);
115+
const [account] = await signerA.getAccounts();
112116
const signerB = signerA;
113117

114118
// Create IBC Client for chain A
115119
const clientA = await IbcClient.connectWithSigner(
116120
chain1RPC,
117121
signerA,
118-
signerA.address,
122+
account.address,
119123
{
120124
gasPrice: GasPrice.fromString("0.25uscrt"),
121125
estimatedBlockTime: 750,
122126
estimatedIndexerTime: 500,
123127
});
124-
// console.group("IBC client for chain A");
128+
console.group("IBC client for chain A");
125129
// console.log(JSON.stringify(clientA));
126130
// console.groupEnd();
131+
await sleep(2000);
127132

128133
// Create IBC Client for chain A
129134
const clientB = await IbcClient.connectWithSigner(
130135
chain2RPC,
131136
signerB,
132-
signerB.address,
137+
account.address,
133138
{
134139
gasPrice: GasPrice.fromString("0.25uscrt"),
135140
estimatedBlockTime: 750,
136141
estimatedIndexerTime: 500,
137142
});
138143
console.group("IBC client for chain B");
144+
await sleep(2000);
139145
// console.log(JSON.stringify(clientB));
140146
// console.groupEnd();
141147

142148
// Create new connectiosn for the 2 clients
143-
console.log("clientA:", clientA);
144-
console.log("clientB:", clientB);
149+
// econsole.log("clientA:", clientA);
150+
// console.log("clientB:", clientB);
145151
const link = await Link.createWithNewConnections(clientA, clientB);
146152

147-
console.group("IBC link details");
148-
console.log(JSON.stringify(link));
149-
console.groupEnd();
153+
await sleep(1000);
154+
155+
// console.group("IBC link details");
156+
// console.log(JSON.stringify(link));
157+
// console.groupEnd();
150158

151159
return link;
152160
}

0 commit comments

Comments
 (0)