-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,42 @@ | ||
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; | ||
import { createPublicClient, http, PublicClient } from 'viem'; | ||
import { solana } from 'viem/chains'; | ||
import waitForExpect from 'wait-for-expect'; | ||
import { Connection, PublicKey } from '@solana/web3.js'; | ||
|
||
import { SolanaContainer, StartedSolanaContainer } from './index'; | ||
|
||
describe('default container', () => { | ||
describe('SolanaContainer', () => { | ||
let container: StartedSolanaContainer; | ||
let connection: Connection; | ||
|
||
beforeAll(async () => { | ||
container = await new SolanaContainer().start(); | ||
connection = new Connection(container.getHostRpcEndpoint(), { | ||
commitment: 'processed', | ||
wsEndpoint: container.getHostWsEndpoint(), | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await container.stop(); | ||
}); | ||
|
||
it('should expose host rpc url', async () => { | ||
expect(container.getHostRpcUrl()).toMatch(/http:\/\/localhost:\d+/); | ||
it('should expose host rpc endpoint', async () => { | ||
expect(container.getHostRpcEndpoint()).toMatch(/http:\/\/localhost:\d+/); | ||
}); | ||
|
||
it('should rpc(eth_blockNumber) via viem', async () => { | ||
const client = createPublicClient({ | ||
chain: solana, | ||
transport: http(container.getHostRpcUrl()), | ||
}); | ||
|
||
const blockNumber = await client.getBlockNumber(); | ||
expect(blockNumber).toBeGreaterThanOrEqual(0n); | ||
it('should get processed block height', async () => { | ||
const blockHeight = await connection.getBlockHeight('processed'); | ||
expect(blockHeight).toBeGreaterThanOrEqual(0); | ||
}); | ||
}); | ||
|
||
describe('auto mining container 2000ms interval', () => { | ||
let container: StartedSolanaContainer; | ||
let client: PublicClient; | ||
|
||
beforeAll(async () => { | ||
container = await new SolanaContainer().withMiningInterval(2000).start(); | ||
client = createPublicClient({ | ||
chain: solana, | ||
transport: http(container.getHostRpcUrl()), | ||
}); | ||
}); | ||
it('should fund address with 5129000000 lamports with confirmation', async () => { | ||
const publicKey = new PublicKey('Emp8JcXpFnCXzdWBC3ChRPtNQHiiQW6kr61wopT3hbNL'); | ||
const lamports = 5_129_000_000; | ||
|
||
afterAll(async () => { | ||
await container.stop(); | ||
}); | ||
const block = await connection.getLatestBlockhash('processed'); | ||
const signature = await connection.requestAirdrop(publicKey, lamports); | ||
await connection.confirmTransaction({ signature, ...block }, 'processed'); | ||
|
||
it('should auto mine block', async () => { | ||
await waitForExpect(async () => { | ||
const blockNumber = await client.getBlockNumber(); | ||
expect(blockNumber).toBeGreaterThan(1n); | ||
}, 6000); | ||
const balance = await connection.getBalance(publicKey, 'processed'); | ||
expect(balance).toStrictEqual(lamports); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.