Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 16, 2023
1 parent 6e294bd commit 9f1d77b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 61 deletions.
6 changes: 3 additions & 3 deletions integration-tests/src/testSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const networkConfigs = {
// 'app_state.slashing.params.downtime_jail_duration': '10s',
// 'app_state.slashing.params.signed_blocks_window': '10',
// 'app_state.staking.params.validator_bond_factor': '10',
// 'app_state.interchainaccounts.host_genesis_state.params.allow_messages': [
// '*',
// ],
'app_state.interchainaccounts.host_genesis_state.params.allow_messages': [
'*',
],
},
config_opts: {
'rpc.laddr': 'tcp://0.0.0.0:26657',
Expand Down
62 changes: 26 additions & 36 deletions integration-tests/testcases/claimer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ describe('Test claim artifact', () => {
let hubClient: any
let deployer: string

let claimerCodeId: number

let creditsAddress: string
let airdropAddress: string
let claimerAddress: string

// untrn sent over transfer channel to gaia
let ibcDenom: string;

let transferChannel: V1IdentifiedChannel;

beforeAll(async () => {
context.park = await setupPark('simple', ['neutron', 'gaia'], true)

Expand All @@ -34,40 +45,24 @@ describe('Test claim artifact', () => {
const accounts = await wallet.getAccounts()
deployer = accounts[0].address;

const neutronCl = new NeutronClient({
neutronClient = new NeutronClient({
apiURL: `http://127.0.0.1:${context.park.ports['neutron'].rest}`,
rpcURL: `127.0.0.1:${context.park.ports['neutron'].rpc}`,
prefix: 'neutron',
})
const hubCl = new GaiaClient({
hubClient = new GaiaClient({
apiURL: `http://127.0.0.1:${context.park.ports['gaia'].rest}`,
rpcURL: `127.0.0.1:${context.park.ports['gaia'].rpc}`,
prefix: 'cosmos'
})


neutronClient = neutronCl
hubClient = hubCl
}, 1000000)

afterAll(async () => {
if (!!context.park) {
console.log('Stopping cosmopark...')
if (context.park) {
await context.park.stop();
}
})

let claimerCodeId: number

let creditsAddress: string
let airdropAddress: string
let claimerAddress: string

// untrn sent over transfer channel to gaia
let ibcDenom: string;

let transferChannel: V1IdentifiedChannel;

it('already has transfer channel', async () => {
const res = await neutronClient.IbcCoreChannelV1.query.queryChannels();
transferChannel = res.data.channels.find(c => c.port_id === 'transfer' && c.state === 'STATE_OPEN')
Expand Down Expand Up @@ -212,13 +207,11 @@ describe('Test claim artifact', () => {
// wait until interchain tx is not in progress
await waitFor(async () => {
const inProgress = await client.queryContractSmart(claimerAddress, { interchain_tx_in_progress: {} })
console.log('iN progress: ' + inProgress);
return !inProgress
}, 500000)

// expect stage to be the old one
const stage = await client.queryContractSmart(claimerAddress, { stage: {} })
console.log('stage should be sendClaimedTokensTOICA: ' + JSON.stringify(stage))
expect(stage).toEqual('send_claimed_tokens_to_i_c_a')

// // expect ica to be still present since timeout in IBC does not close ICA
Expand All @@ -230,7 +223,6 @@ describe('Test claim artifact', () => {
const callbackStates = await client.queryContractSmart(claimerAddress, { ibc_callback_states: {} })
expect(callbackStates).toBeDefined()
expect(callbackStates.length).toEqual(1)
console.log('timeout: ' + JSON.stringify(callbackStates[0]))
expect(callbackStates[0].timeout[0].source_port).toEqual('transfer');

// return back old values
Expand All @@ -243,11 +235,9 @@ describe('Test claim artifact', () => {
}, 1000000)

it('step 2 - send claimed tokens to ICA account', async () => {
console.log('before sending')
await client.execute(deployer, claimerAddress, {
send_claimed_tokens_to_i_c_a: {},
}, 'auto', '', [{amount: '5000', denom: 'untrn'}])
console.log('after sending')

// wait until interchain tx is not in progress
await waitFor(async () => {
Expand All @@ -261,9 +251,7 @@ describe('Test claim artifact', () => {

// wait for balance to be present on hub ica
const ica = await client.queryContractSmart(claimerAddress, { interchain_account: {} })
console.log('before querying balance: ' + ica.address)
const icaBalance = await hubClient.CosmosBankV1Beta1.query.queryBalance(ica.address, { denom: ibcDenom })
console.log('after querying balance')
// 9000 initially + refunded 2500 from ack fee in step 2 = 11500
expect(icaBalance.data.balance.amount).toEqual('11500')

Expand Down Expand Up @@ -308,8 +296,7 @@ describe('Test claim artifact', () => {
const callbackStates = await client.queryContractSmart(claimerAddress, { ibc_callback_states: {} })
expect(callbackStates.length).toEqual(3)
expect(callbackStates[2].timeout[0].sequence).toEqual(1)
console.log('response: ' + JSON.stringify(callbackStates[2].timeout))
expect(callbackStates[2].timeout[0].source_port).toEqual(ica.source_port_id);
expect(callbackStates[2].timeout[0].source_port).toEqual(ica.port_id);

// ICA is removed
const icaAfter = await client.queryContractSmart(claimerAddress, { interchain_account: {} })
Expand All @@ -336,6 +323,7 @@ describe('Test claim artifact', () => {
expect(stage).toEqual('fund_community_pool')
})

// TODO: can use allowed/not allowed params? that's complex tho cause need to change params on gaia
it.skip('step 3 with error - fund community pool', async () => {
// TODO: change transfer amount to bigger value (15000)

Expand All @@ -355,28 +343,30 @@ describe('Test claim artifact', () => {
it('step 3 - fund community pool', async () => {
await client.execute(deployer, claimerAddress, {
fund_community_pool: {},
}, 'auto', 'fund community pool', [{ amount: '8000', denom: 'untrn' }])
}, 'auto', '', [{ amount: '8000', denom: 'untrn' }])

// wait until interchain tx is not in progress
await waitFor(async () => {
const inProgress = await client.queryContractSmart(claimerAddress, { interchain_tx_in_progress: {} })
return !inProgress
}, 500000)

// await stage to be 'done'
// should return callback
const ica = await client.queryContractSmart(claimerAddress, { interchain_account: {} })
const callbackStates = await client.queryContractSmart(claimerAddress, { ibc_callback_states: {} })
expect(callbackStates[3].response[0].source_port).toEqual(ica.port_id)

// stage should be 'done'
const stage = await client.queryContractSmart(claimerAddress, { stage: {} })
expect(stage).toEqual('done')

// expect balance to be 0 on ICA
const ica = await client.queryContractSmart(claimerAddress, { interchain_account: {} })
// expect balance to be 0 on ICA after funding
const icaBalance = await hubClient.CosmosBankV1Beta1.query.queryBalance(ica.address, { denom: ibcDenom })
console.log('after querying balance')
// 9000 initially + refunded 2500 from ack fee in step 2 = 11500
expect(icaBalance.data.balance.amount).toEqual('0')

// TODO: check that community pool account is funded
// expect community pool to have transferred funds
const moduleAccountResponse = await hubClient.CosmosAuthV1Beta1.query.queryModuleAccountByName('distribution')
const moduleAccount = ModuleAccount.fromJSON(moduleAccountResponse.data.account).baseAccount.address
const moduleAccount = moduleAccountResponse.data.account.base_account.address
const icaBalanceInPool = await hubClient.CosmosBankV1Beta1.query.queryBalance(moduleAccount, { denom: ibcDenom })
expect(icaBalanceInPool.data.balance.amount).toEqual('11500')
}, 1000000)
Expand Down
35 changes: 14 additions & 21 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,26 +321,17 @@ fn sudo_response(

save_ibc_callback_state(
deps.storage,
IbcCallbackState::Response(request, env.block.height),
IbcCallbackState::Response(request.clone(), env.block.height),
)?;

let is_transfer = source_port == TRANSFER_PORT;
if is_transfer {
if source_port == TRANSFER_PORT {
STAGE.save(deps.storage, &Stage::FundCommunityPool)?;
} else {
let parsed_data = decode_acknowledgement_response(data)?;
for item in parsed_data {
let item_type = item.msg_type.as_str();
deps.api
.debug(&format!("WASMDEBUG: item_type = {}", item_type));
match item_type {
MSG_FUND_COMMUNITY_POOL => {
STAGE.save(deps.storage, &Stage::Done)?;
}
_ => {
continue;
}
}
}

// is ICA transaction
if let Some(ica) = INTERCHAIN_ACCOUNT.load(deps.storage)? {
if source_port == ica.port_id {
STAGE.save(deps.storage, &Stage::Done)?;
}
}

Expand Down Expand Up @@ -378,7 +369,7 @@ fn sudo_timeout(deps: DepsMut, env: Env, request: RequestPacket) -> StdResult<Re

// ICA transactions timeout closes the channel
if let Some(ica) = INTERCHAIN_ACCOUNT.load(deps.storage)? {
if source_port == ica.source_port_id {
if source_port == ica.port_id {
INTERCHAIN_ACCOUNT.save(deps.storage, &None)?;
}
}
Expand All @@ -390,8 +381,8 @@ fn sudo_open_ack(
deps: DepsMut,
_env: Env,
port_id: String,
_channel_id: String,
_counterparty_channel_id: String,
channel_id: String,
counterparty_channel_id: String,
counterparty_version: String,
) -> StdResult<Response> {
let parsed_version: Result<OpenAckVersion, _> =
Expand All @@ -401,7 +392,9 @@ fn sudo_open_ack(
deps.storage,
&Some(InterchainAccount {
address: parsed_version.address,
source_port_id: port_id,
port_id,
channel_id,
counterparty_channel_id,
}),
)?;
INTERCHAIN_TX_IN_PROGRESS.save(deps.storage, &false)?;
Expand Down
4 changes: 3 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ pub struct Config {
pub struct InterchainAccount {
// ica address on remote network
pub address: String,
pub source_port_id: String,
pub port_id: String,
pub channel_id: String,
pub counterparty_channel_id: String,
}

// TODO: can we import it from library?
Expand Down

0 comments on commit 9f1d77b

Please sign in to comment.