mirror of
https://github.com/zkopru-network/zkopru.git
synced 2026-01-14 16:58:01 -05:00
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
/**
|
|
* @jest-environment node
|
|
*/
|
|
/* eslint-disable jest/no-hooks */
|
|
import Web3 from 'web3'
|
|
import { WebsocketProvider } from 'web3-core'
|
|
import { Container } from 'node-docker-api/lib/container'
|
|
import { soliditySha3Raw } from 'web3-utils'
|
|
import { DB, SQLiteConnector, schema } from '~database/node'
|
|
import { ZkAccount } from '~account'
|
|
import { sleep } from '~utils'
|
|
import { readFromContainer, buildAndGetContainer } from '~utils-docker'
|
|
import { LightNode, HttpBootstrapHelper } from '~core'
|
|
|
|
describe('integration test to run testnet', () => {
|
|
const testName = 'lightnodetest'
|
|
let address: string
|
|
let container: Container
|
|
let lightNode: LightNode
|
|
let wsProvider: WebsocketProvider
|
|
let mockup: DB
|
|
beforeAll(async () => {
|
|
mockup = await SQLiteConnector.create(schema, ':memory:')
|
|
// It may take about few minutes. If you want to skip building image,
|
|
// run `yarn pull:images` on the root directory
|
|
container = await buildAndGetContainer({
|
|
compose: [__dirname, '../../../../compose'],
|
|
service: 'contracts',
|
|
option: { containerName: testName },
|
|
})
|
|
await container.start()
|
|
const deployed = await readFromContainer(
|
|
container,
|
|
'/proj/build/deployed/Zkopru.json',
|
|
)
|
|
address = JSON.parse(deployed.toString()).address
|
|
const status = await container.status()
|
|
const containerIP = (status.data as {
|
|
NetworkSettings: { IPAddress: string }
|
|
}).NetworkSettings.IPAddress
|
|
await sleep(2000)
|
|
wsProvider = new Web3.providers.WebsocketProvider(
|
|
`ws://${containerIP}:5000`,
|
|
{ reconnect: { auto: true } },
|
|
)
|
|
async function waitConnection() {
|
|
return new Promise<void>(res => {
|
|
if (wsProvider.connected) res()
|
|
wsProvider.on('connect', res)
|
|
})
|
|
}
|
|
await waitConnection()
|
|
}, 3600000)
|
|
afterAll(async () => {
|
|
await container.stop()
|
|
await container.delete()
|
|
await mockup.close()
|
|
wsProvider.disconnect(0, 'close connection')
|
|
}, 20000)
|
|
describe('light node', () => {
|
|
it('should be defined', async () => {
|
|
const accounts: ZkAccount[] = [
|
|
new ZkAccount(soliditySha3Raw('sample private key')),
|
|
]
|
|
lightNode = await LightNode.new({
|
|
provider: wsProvider,
|
|
address,
|
|
db: mockup,
|
|
accounts,
|
|
bootstrapHelper: new HttpBootstrapHelper('http://localhost:8888'),
|
|
})
|
|
expect(lightNode).toBeDefined()
|
|
}, 60000)
|
|
})
|
|
})
|