Skip to content
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

enable tests #152

Merged
merged 7 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
18 changes: 18 additions & 0 deletions helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ const { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp } = withExpec
export { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp }

export * from '@acala-network/chopsticks-testing'

const defaultTimeout = process.env.CI ? 180000 : 120000

export const jest = (filename: string) => {
const { beforeEach, afterEach, afterAll, expect, describe, it } = (Bun as any).jest(filename) // workaround https://github.com/oven-sh/bun/issues/7873

const newIt = (name: string, fn: any, timeout = defaultTimeout) => {
it(
name,
async () => {
await fn()
},
timeout,
)
}

return { beforeEach, afterEach, afterAll, expect, describe, it: newIt }
}
2 changes: 1 addition & 1 deletion networks/acala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
// avoid impact test outcome
$removePrefix: ['redeemRequests', 'unbondings', 'toBondPool'],
// so that bump era won't trigger unbond
relayChainCurrentEra: '0x64000000',
relayChainCurrentEra: 100,
},
PolkadotXcm: {
// avoid sending xcm version change notifications to makes things faster
Expand Down
1 change: 1 addition & 0 deletions networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ for (const def of Object.values(networkDefs)) {
endpoint: process.env[`${upperName}_ENDPOINT`] ?? endpoint,
db: process.env.DB_PATH,
port: 0,
allowUnresolvedImports: true,
...setupConfig.options,
...options,
}
Expand Down
2 changes: 1 addition & 1 deletion networks/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Vars = {
export default {
polkadot: {
name: 'parallel' as const,
endpoint: 'wss://rpc.parallel.fi',
endpoint: 'wss://parallel-rpc.dwellir.com',
ausd: 104,
acalaNativeToken: 108,
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@polkadot/api": "^10.11.1"
},
"dependencies": {
"@acala-network/chopsticks": "^0.9.5-3",
"@acala-network/chopsticks-testing": "^0.9.5-3",
"@acala-network/chopsticks": "^0.9.6-1",
"@acala-network/chopsticks-testing": "^0.9.6-1",
"@acala-network/sdk": "^4.1.9-10",
"@acala-network/sdk-core": "^4.1.9-10",
"@polkadot/api": "^10.11.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/parallel.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extensions:
client:
endpoints:
- wss://rpc.parallel.fi:443
- wss://parallel-rpc.dwellir.com
event_bus:
substrate_api:
stale_timeout_seconds: 60
Expand Down
18 changes: 18 additions & 0 deletions tests/acala/__snapshots__/homa.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ exports[`karura homa with latest block Homa stake works: ump 1`] = `
},
{
"transact": {
"call": {
"encoded": "(hex)",
},
"originType": "SovereignAccount",
"requireWeightAtMost": "(number)",
},
Expand Down Expand Up @@ -328,12 +331,18 @@ exports[`karura homa with specific block unbond withdraw works: ump 1`] = `
},
{
"transact": {
"call": {
"encoded": "0x18010200060305000000",
},
"originType": "SovereignAccount",
"requireWeightAtMost": 20000000000,
},
},
{
"transact": {
"call": {
"encoded": "0x1801020004030070617261d00700000000000000000000000000000000000000000000000000000b07db23d49c4c",
},
"originType": "SovereignAccount",
"requireWeightAtMost": 20000000000,
},
Expand Down Expand Up @@ -523,6 +532,9 @@ exports[`acala homa with latest block Homa stake works: ump 1`] = `
},
{
"transact": {
"call": {
"encoded": "(hex)",
},
"originType": "SovereignAccount",
"requireWeightAtMost": "(number)",
},
Expand Down Expand Up @@ -714,12 +726,18 @@ exports[`acala homa with specific block unbond withdraw works: ump 1`] = `
},
{
"transact": {
"call": {
"encoded": "0x1a010000070305000000",
},
"originType": "SovereignAccount",
"requireWeightAtMost": 10000000000,
},
},
{
"transact": {
"call": {
"encoded": "0x1a01000005030070617261d00700000000000000000000000000000000000000000000000000000bd76e3b5f030a",
},
"originType": "SovereignAccount",
"requireWeightAtMost": 10000000000,
},
Expand Down
11 changes: 5 additions & 6 deletions tests/acala/aggregated-dex.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { afterEach, beforeEach, describe, it } from 'bun:test'
import { bnToHex } from '@polkadot/util'
import { sendTransaction } from '@acala-network/chopsticks-testing'

import { Network, createContext, createNetworks } from '../../networks'
import { checkEvents } from '../../helpers'
import { checkEvents, jest } from '../../helpers'

import { acala, karura } from '../../networks/acala'

const { beforeEach, afterEach, describe, it } = jest(import.meta.path)

for (const { name, swapPath } of [
{
name: 'karura',
Expand Down Expand Up @@ -46,13 +46,12 @@ for (const { name, swapPath } of [
const toBondPool: bigint = ((await apiAt.query.homa.toBondPool()) as any).toBigInt()
await chain.dev.setStorage({
Homa: {
toBondPool: bnToHex(toBondPool + 10n * 10n ** 10n, { bitLength: 128, isLe: true }),
toBondPool: toBondPool + 10n * 10n ** 10n,
},
})
})

afterEach(async () => {
console.log('teardown')
await chain.teardown()
})

Expand All @@ -64,6 +63,6 @@ for (const { name, swapPath } of [
await chain.chain.newBlock()

await checkEvents(tx, 'dex').redact({ number: true }).toMatchSnapshot()
}, 120000)
})
})
}
7 changes: 4 additions & 3 deletions tests/acala/dex.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { afterAll, beforeEach, describe, it } from 'bun:test'
import { sendTransaction, testingPairs } from '@acala-network/chopsticks-testing'

import { checkEvents } from '../../helpers'
import { checkEvents, jest } from '../../helpers'
import { createNetworks } from '../../networks'

import { acala, karura } from '../../networks/acala'
import { query } from '../../helpers/api'

const { beforeEach, afterAll, describe, it } = jest(import.meta.path)

for (const { name, swapPair } of [
{
name: 'karura',
Expand Down Expand Up @@ -78,7 +79,7 @@ for (const { name, swapPair } of [
await checkEvents(tx1, 'dex', 'incentives', 'tokens')
.redact({ number: true })
.toMatchSnapshot('removeLiquidity')
}, 120000)
})
}
})
}
23 changes: 12 additions & 11 deletions tests/acala/homa.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { beforeEach, describe, it } from 'bun:test'
import { sendTransaction, testingPairs } from '@acala-network/chopsticks-testing'

import { Network, createNetworks } from '../../networks'
import { checkEvents, checkSystemEvents, checkUmp } from '../../helpers'
import { checkEvents, checkSystemEvents, checkUmp, jest } from '../../helpers'

const { beforeEach, afterEach, describe, it } = jest(import.meta.path)

for (const { name, relay, unbond } of [
{
name: 'karura',
relay: 'kusama',
unbond: { para: 4981210, relay: 19226890, era: '0x91150000' },
unbond: { para: 4981210, relay: 19226890, era: 5521 },
},
{
name: 'acala',
relay: 'polkadot',
unbond: { para: 4225795, relay: 16829283, era: '0x90040000' },
unbond: { para: 4225795, relay: 16829283, era: 1168 },
},
] as const) {
describe(`${name} homa`, async () => {
Expand All @@ -31,11 +32,11 @@ for (const { name, relay, unbond } of [

relaychain = relaychain1
parachain = parachain1
})

return async () => {
await relaychain.teardown()
await parachain.teardown()
}
afterEach(async () => {
await relaychain.teardown()
await parachain.teardown()
})

it('Homa stake works', async () => {
Expand All @@ -55,7 +56,7 @@ for (const { name, relay, unbond } of [
await checkSystemEvents(relaychain, 'ump', 'staking', 'messageQueue')
.redact({ address: true, number: true })
.toMatchSnapshot()
}, 120000)
})

it('Homa redeem unbond works', async () => {
const tx0 = await sendTransaction(
Expand All @@ -75,7 +76,7 @@ for (const { name, relay, unbond } of [
await checkSystemEvents(relaychain, 'ump', 'staking', 'messageQueue')
.redact({ address: true })
.toMatchSnapshot()
}, 120000)
})
})

describe('with specific block', () => {
Expand Down Expand Up @@ -114,7 +115,7 @@ for (const { name, relay, unbond } of [

await relaychain.chain.newBlock()
await checkSystemEvents(relaychain, 'ump', 'staking', 'messageQueue').toMatchSnapshot()
}, 120000)
})
})
})
}
28 changes: 13 additions & 15 deletions tests/acala/stable-asset.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { beforeEach, describe, it } from 'bun:test'
import { bnToHex } from '@polkadot/util'
import { sendTransaction } from '@acala-network/chopsticks-testing'

import { Network, createContext, createNetworks } from '../../networks'
import { checkEvents, checkSystemEvents } from '../../helpers'
import { checkEvents, checkSystemEvents, jest } from '../../helpers'
import { query } from '../../helpers/api'

const { beforeEach, afterEach, describe, it } = jest(import.meta.path)

for (const name of ['karura', 'acala'] as const) {
describe(`${name} stable asset`, async () => {
let chain: Network
Expand All @@ -22,11 +22,13 @@ for (const name of ['karura', 'acala'] as const) {
const toBondPool: bigint = ((await apiAt.query.homa.toBondPool()) as any).toBigInt()
await chain.dev.setStorage({
Homa: {
toBondPool: bnToHex(toBondPool + 10n * 10n ** 10n, { bitLength: 128, isLe: true }),
toBondPool: toBondPool + 100n * 10n ** 10n,
},
})
})

return async () => chain.teardown()
afterEach(async () => {
await chain.teardown()
})

it('swap', async () => {
Expand Down Expand Up @@ -64,19 +66,15 @@ for (const name of ['karura', 'acala'] as const) {
event: 'RedeemedProportion',
},
] as const) {
it(
name,
async () => {
const balData: any = await query.tokens({ StableAssetPoolToken: 0 })(chain, alice.address)
it(name, async () => {
const balData: any = await query.tokens({ StableAssetPoolToken: 0 })(chain, alice.address)

const tx0 = await sendTransaction(tx(balData.free).signAsync(alice))
const tx0 = await sendTransaction(tx(balData.free).signAsync(alice))

await chain.chain.newBlock()
await chain.chain.newBlock()

await checkEvents(tx0, { section: 'stableAsset', method: event }).redact({ number: true }).toMatchSnapshot()
},
120000,
)
await checkEvents(tx0, { section: 'stableAsset', method: event }).redact({ number: true }).toMatchSnapshot()
})
}
})

Expand Down
Loading