-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(2.8): ibc hooks #212
test(2.8): ibc hooks #212
Changes from 1 commit
8f36b22
ab5afac
baf15e3
de74832
2f0c6cd
9995f15
6ec43a5
ce9ba83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ module.exports = { | |
testMatch: ['**/*.test.ts'], | ||
verbose: true, | ||
testTimeout: 30000, | ||
maxConcurrency: 4, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
export const SAFE_VOTING_PERIOD_TIME = 4100; | ||
export const SAFE_IBC_TRANSFER = 4100; | ||
export const SAFE_BLOCK_INCLUSION_TIME = 1100; | ||
|
||
export const blockInclusion = () => new Promise((resolve) => setTimeout(() => resolve(SAFE_BLOCK_INCLUSION_TIME), SAFE_BLOCK_INCLUSION_TIME)); | ||
export const votingPeriod = () => new Promise((resolve) => setTimeout(() => resolve(SAFE_VOTING_PERIOD_TIME), SAFE_VOTING_PERIOD_TIME)); | ||
export const ibcTransfer = () => new Promise((resolve) => setTimeout(() => resolve(SAFE_IBC_TRANSFER), SAFE_IBC_TRANSFER)); | ||
export const votingPeriod = () => new Promise((resolve) => setTimeout(() => resolve(SAFE_VOTING_PERIOD_TIME), SAFE_VOTING_PERIOD_TIME)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Coin, Coins, MsgInstantiateContract, MsgStoreCode, MsgTransfer } from "@terra-money/feather.js"; | ||
import { ibcTransfer, getMnemonics, getLCDClient, blockInclusion } from "../../helpers"; | ||
import fs from "fs"; | ||
import path from 'path'; | ||
import moment from "moment"; | ||
|
||
describe("IbcHooks Module (github.com/cosmos/ibc-apps/modules/ibc-hooks/v7) ", () => { | ||
// Prepare the LCD and wallets. chain1Wallet is the one that will | ||
// deploy the contract on chain 1 and chain2Wallet will be used | ||
// to send IBC messages from chain 2 to interact with the contract. | ||
const LCD = getLCDClient(); | ||
const accounts = getMnemonics(); | ||
const chain1Wallet = LCD.chain1.wallet(accounts.ibcHooksMnemonic); | ||
const chain2Wallet = LCD.chain2.wallet(accounts.ibcHooksMnemonic); | ||
const walletAddress = accounts.ibcHooksMnemonic.accAddress("terra"); | ||
let contractAddress: string; | ||
|
||
// Read the counter contract, store on chain, | ||
// instantiate to be used in the following tests | ||
// and finally save the contract address. | ||
beforeAll(async () => { | ||
let tx = await chain1Wallet.createAndSignTx({ | ||
msgs: [new MsgStoreCode( | ||
walletAddress, | ||
fs.readFileSync(path.join(__dirname, "/../../contracts/counter.wasm")).toString("base64"), | ||
)], | ||
chainID: "test-1", | ||
}); | ||
|
||
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); | ||
await blockInclusion(); | ||
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; | ||
let codeId = Number(txResult.logs[0].events[1].attributes[1].value); | ||
expect(codeId).toBeDefined(); | ||
|
||
const msgInstantiateContract = new MsgInstantiateContract( | ||
walletAddress, | ||
walletAddress, | ||
codeId, | ||
{ count: 0 }, | ||
Coins.fromString("1uluna"), | ||
"counter contract " + Math.random(), | ||
); | ||
|
||
tx = await chain1Wallet.createAndSignTx({ | ||
msgs: [msgInstantiateContract], | ||
chainID: "test-1", | ||
}); | ||
result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); | ||
await blockInclusion(); | ||
txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; | ||
contractAddress = txResult.logs[0].events[4].attributes[0].value; | ||
expect(contractAddress).toBeDefined(); | ||
}) | ||
|
||
describe("Must send IBC messages from chain 2 to chain 1", () => { | ||
test('must incrementing the counter', async () => { | ||
try { | ||
const resw = await LCD.chain1.wasm.contractQuery( | ||
contractAddress, | ||
{ | ||
"get_count": { | ||
"addr": walletAddress | ||
} | ||
} | ||
); | ||
console.log(JSON.stringify(resw)); | ||
let tx = await chain2Wallet.createAndSignTx({ | ||
msgs: [ | ||
new MsgTransfer( | ||
"transfer", | ||
"channel-0", | ||
Coin.fromString("10000000uluna"), | ||
walletAddress, | ||
contractAddress, | ||
undefined, | ||
moment.utc().add(1.5, "day").unix().toString() + "000000000", | ||
`{"wasm":{"contract": "${contractAddress}" ,"msg": {"increment": {}}}}` | ||
), | ||
], | ||
chainID: "test-2", | ||
}); | ||
let result = await LCD.chain2.tx.broadcastSync(tx, "test-2"); | ||
await ibcTransfer(); | ||
let txResult = await LCD.chain2.tx.txInfo(result.txhash, "test-2") as any; | ||
expect(txResult.logs[0].eventsByType.ibc_transfer) | ||
.toStrictEqual({ | ||
"sender": [walletAddress], | ||
"receiver": [contractAddress], | ||
"amount": ["10000000"], | ||
"denom": ["uluna"], | ||
"memo": [`{"wasm":{"contract": "${contractAddress}" ,"msg": {"increment": {}}}}`] | ||
}); | ||
|
||
const res = await LCD.chain1.wasm.contractQuery( | ||
contractAddress, | ||
{ | ||
"get_count": { | ||
"addr": walletAddress | ||
} | ||
} | ||
); | ||
console.log(JSON.stringify(res)); | ||
} | ||
catch (e) { | ||
console.log(e) | ||
} | ||
}) | ||
}) | ||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emidev98 is this deletion expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javiersuweijie yes because the folder structure was created by mistake as wasmd instead of wasm