Skip to content

Commit

Permalink
fix sdk e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-sven committed Aug 27, 2024
1 parent 349e4fb commit 3ab71bd
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 64 deletions.
4 changes: 2 additions & 2 deletions sdk/typescript/rooch-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"vitest": "vitest",
"test": "pnpm test:unit && pnpm test:e2e",
"test:unit": "vitest run src",
"test:e2e": "pnpm prepare:e2e && wait-on tcp:0.0.0.0:6767 -l --timeout 180000 && vitest run e2e; pnpm stop:e2e",
"test:e2e": "pnpm prepare:e2e && wait-on tcp:0.0.0.0:6767 -l --timeout 180000 && vitest run e2e || exit 1; pnpm stop:e2e",
"test:e2e:nowait": "vitest run e2e",
"prepare:e2e": "nohup cargo run --bin rooch server start -n local -d TMP --port 6767 > /dev/null 2>&1 &",
"stop:e2e": "lsof -ti:6767 | xargs kill",
"stop:e2e": "lsof -ti:6767 | tee /dev/stderr | xargs -r kill -9",
"prepublishOnly": "pnpm build",
"size": "size-limit",
"analyze": "size-limit --why",
Expand Down
28 changes: 12 additions & 16 deletions sdk/typescript/rooch-sdk/test-e2e/case/bitcoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ describe('Bitcoin Assets API', () => {
await testBox.loadRoochEnv()
})

afterAll(() => {
testBox.unloadContainer()
afterAll(async () => {
testBox.cleanEnv()
})

it('query utxo should be success', async () => {
const addr = testBox.keypair.getSchnorrPublicKey().buildAddress(1, BitcoinNetowkType.Regtest).toStr()
console.log(addr)
const addr = testBox.keypair
.getSchnorrPublicKey()
.buildAddress(1, BitcoinNetowkType.Regtest)
.toStr()
const result = await testBox.bitcoinContainer?.executeRpcCommand('generatetoaddress', [
'50',
addr,
Expand Down Expand Up @@ -81,17 +83,11 @@ describe('Bitcoin Assets API', () => {
})
expect(utxos.data.length).toBeGreaterThan(0)

// first make sure don’t break
try {
const inscriptions = await testBox.getClient().queryInscriptions({
filter: {
owner: addr,
},
})
// TODO: check inscriptions result
expect(inscriptions).toBeDefined()
} catch (e) {
expect(e).toBeUndefined()
}
const inscriptions = await testBox.getClient().queryInscriptions({
filter: {
owner: addr,
},
})
expect(inscriptions.data.length).toBeGreaterThan(0)
})
})
8 changes: 7 additions & 1 deletion sdk/typescript/rooch-sdk/test-e2e/case/checkpoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { Args } from '../../src/bcs/index.js'
import { Secp256k1Keypair } from '../../src/keypairs/index.js'
import { BitcoinAddress, BitcoinNetowkType } from '../../src/address/index.js'
Expand All @@ -17,6 +17,10 @@ describe('Checkpoints Reading API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 20 in sdk/typescript/rooch-sdk/test-e2e/case/checkpoint.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Get latest rpc version eq local version', async () => {
const resultSN = await testBox.getClient().getRpcApiVersion()

Expand Down Expand Up @@ -147,6 +151,8 @@ describe('Checkpoints Reading API', () => {

expect(await testBox.signAndExecuteTransaction(tx)).toBeTruthy()

await testBox.delay(3)

const result1 = await testBox.getClient().getEvents({
eventHandleType: `${await testBox.defaultCmdAddress()}::event_test::WithdrawEvent`,
limit: '1',
Expand Down
44 changes: 31 additions & 13 deletions sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { TestBox } from '../setup.js'
import { Transaction } from '../../src/transactions/index.js'
import { Secp256k1Keypair } from '../../src/keypairs/index.js'
Expand All @@ -14,6 +14,10 @@ describe('Checkpoints Coin API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 17 in sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Cmd publish package should be success', async () => {
const result = await testBox.cmdPublishPackage('../../../examples/coins', {
namedAddresses: 'coins=default',
Expand All @@ -22,26 +26,40 @@ describe('Checkpoints Coin API', () => {
expect(result).toBeTruthy()
})

it('Cmd publish package should be success', async () => {
testBox.roochCommand(
'move run --function default::fixed_supply_coin::faucet --args object:default::fixed_supply_coin::Treasury',
)
it('Check balances should be success', async () => {

Check failure on line 30 in sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Delete `⏎`
let result = await testBox.getClient().getBalances({
owner: await testBox.defaultCmdAddress(),
limit: '1',
const tx = new Transaction()
tx.callFunction({
target: `${await testBox.defaultCmdAddress()}::fixed_supply_coin::faucet`,
args: [
Args.object({
address: await testBox.defaultCmdAddress(),
module: 'fixed_supply_coin',
name:'Treasury'

Check failure on line 38 in sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Replace `'Treasury'` with `·'Treasury',`
})

Check failure on line 39 in sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `,`
]

Check failure on line 40 in sdk/typescript/rooch-sdk/test-e2e/case/coin.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `,`
})

expect(result.has_next_page).toBeTruthy()
let result = await testBox.signAndExecuteTransaction(tx)
expect(result).toBeTruthy()

await testBox.delay(3)

let result1 = await testBox.getClient().getBalances({
owner: await testBox.defaultCmdAddress(),
owner: testBox.address().toHexAddress(),
limit: '1',
})

expect(result1.has_next_page).toBeTruthy()

let result2 = await testBox.getClient().getBalances({
owner: testBox.address().toHexAddress(),
limit: '1',
cursor: result.next_cursor,
cursor: result1.next_cursor,
})

expect(result1.has_next_page).toBeFalsy()
expect(result1.data.length === 1).toBeTruthy()
expect(result2.has_next_page).toBeFalsy()
expect(result2.data.length === 1).toBeTruthy()
})

it('Transfer gas coin should be success', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { TestBox } from '../setup.js'
import { Args } from '../../src/bcs/index.js'
import { Transaction } from '../../src/transactions/index.js'
Expand All @@ -14,6 +14,10 @@ describe('Checkpoints Example Entry Function', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 17 in sdk/typescript/rooch-sdk/test-e2e/case/example-entry-function.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Cmd publish package should be success', async () => {
const result = await testBox.cmdPublishPackage('../../../examples/entry_function_arguments/')

Expand Down
6 changes: 5 additions & 1 deletion sdk/typescript/rooch-sdk/test-e2e/case/module-abi.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, it, expect } from 'vitest'
import { beforeAll, describe, it, expect, afterAll } from 'vitest'

import { TestBox } from '../setup.js'

Expand All @@ -12,6 +12,10 @@ describe('Module Abi API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 15 in sdk/typescript/rooch-sdk/test-e2e/case/module-abi.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Get module abi', async () => {
const result = await testBox.getClient().getModuleAbi({
moduleAddr: '0x3',
Expand Down
6 changes: 5 additions & 1 deletion sdk/typescript/rooch-sdk/test-e2e/case/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { TestBox } from '../setup.js'
import { Transaction } from '../../src/transactions/index.js'

Expand All @@ -12,6 +12,10 @@ describe('Checkpoints Session API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 15 in sdk/typescript/rooch-sdk/test-e2e/case/session.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Create session should be success', async () => {
const session = await testBox.getClient().createSession({
sessionArgs: {
Expand Down
6 changes: 5 additions & 1 deletion sdk/typescript/rooch-sdk/test-e2e/case/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { TestBox } from '../setup.js'
import { Transaction } from '../../src/transactions/index.js'

Expand All @@ -12,6 +12,10 @@ describe('Checkpoints Transaction API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {

Check failure on line 15 in sdk/typescript/rooch-sdk/test-e2e/case/transaction.test.ts

View workflow job for this annotation

GitHub Actions / Check-Build-Test

Insert `·`
testBox.cleanEnv()
})

it('Call function with bitcoin auth should be success', async () => {
const tx = new Transaction()
tx.callFunction({
Expand Down
6 changes: 5 additions & 1 deletion sdk/typescript/rooch-sdk/test-e2e/case/transfer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

import { beforeAll, describe, expect, it } from 'vitest'
import { beforeAll, describe, expect, it, afterAll } from 'vitest'
import { TestBox } from '../setup.js'
import { Transaction } from '../../src/transactions/index.js'
import { Secp256k1Keypair } from '../../src/keypairs/index.js'
Expand All @@ -14,6 +14,10 @@ describe('Checkpoints Transfer API', () => {
testBox = TestBox.setup()
})

afterAll(async ()=> {
testBox.cleanEnv()
})

it('Transfer gas coin should be success', async () => {
const amount = BigInt(10000000)
const coinType = '0x3::gas_coin::GasCoin'
Expand Down
27 changes: 6 additions & 21 deletions sdk/typescript/rooch-sdk/test-e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import * as fs from 'fs'
import tmp from 'tmp'
import { RoochAddress } from '../src/address/index.js'
import { getRoochNodeUrl, RoochClient } from '../src/client/index.js'
import { Secp256k1Keypair } from '../src/keypairs/index.js'
Expand All @@ -14,12 +13,13 @@ import { TestBox as TestBoxA, RoochContainer } from '@roochnetwork/test-suite'
export const DEFAULT_NODE_URL = import.meta.env.VITE_FULLNODE_URL ?? getRoochNodeUrl('localnet')

export class TestBox extends TestBoxA {
private client?: RoochClient
private client: RoochClient
keypair: Secp256k1Keypair

constructor(keypair: Secp256k1Keypair) {
super()
this.keypair = keypair
this.client = new RoochClient({ url: DEFAULT_NODE_URL })
}

static setup(): TestBox {
Expand All @@ -32,26 +32,14 @@ export class TestBox extends TestBoxA {
port: number = 6768,
): Promise<void> {
await super.loadRoochEnv(target, port)

this.client = new RoochClient({
url: `http://127.0.0.1:${port}`,
})
return
}

getClient(url = DEFAULT_NODE_URL): RoochClient {
if (url === DEFAULT_NODE_URL) {
if (!this.client) {
this.client = new RoochClient({
url,
})
}
return this.client
}

return new RoochClient({
url,
})
getClient(): RoochClient {
return this.client
}

address(): RoochAddress {
Expand All @@ -76,20 +64,17 @@ export class TestBox extends TestBoxA {
namedAddresses: 'rooch_examples=default',
},
) {
tmp.setGracefulCleanup()

const tmpDir = tmp.dirSync({ unsafeCleanup: true })
const namedAddresses = options.namedAddresses.replaceAll(
'default',
box.address().toHexAddress(),
)
this.roochCommand(
`move build -p ${packagePath} --named-addresses ${namedAddresses} --install-dir ${tmpDir.name} --export --json`,
`move build -p ${packagePath} --named-addresses ${namedAddresses} --install-dir ${this.tmpDir.name} --export --json`,
)

let fileBytes: Uint8Array
try {
fileBytes = fs.readFileSync(tmpDir.name + '/package.blob')
fileBytes = fs.readFileSync(this.tmpDir.name + '/package.blob')
const tx = new Transaction()
tx.callFunction({
target: '0x2::module_store::publish_modules_entry',
Expand Down
File renamed without changes.
Loading

0 comments on commit 3ab71bd

Please sign in to comment.