Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukassF committed Oct 4, 2024
1 parent 9e26c80 commit 8736559
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@nightlylabs/nightly-connect-polkadot": "0.0.16",
"@nightlylabs/nightly-connect-solana": "0.0.3",
"@nightlylabs/nightly-connect-sui": "0.1.0",
"@nightlylabs/wallet-selector-aptos": "0.1.11",
"@nightlylabs/wallet-selector-base": "^0.4.2",
"@nightlylabs/wallet-selector-aptos": "^0.1.12",
"@nightlylabs/wallet-selector-base": "^0.4.3",
"@nightlylabs/wallet-selector-polkadot": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.8",
"@nightlylabs/wallet-selector-sui": "0.4.0",
Expand Down
4 changes: 4 additions & 0 deletions sdk/packages/aptos/src/http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,9 @@ describe('Aptos http-client tests', () => {
sessionId: app.sessionId,
newNetwork: payload
})

await smartDelay()
const isSuccess = (await _changedNetwork).status === UserResponseStatus.APPROVED
assert(isSuccess)
})
})
4 changes: 2 additions & 2 deletions sdk/packages/selector-aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-aptos",
"version": "0.1.11",
"version": "0.1.12",
"description": "",
"type": "module",
"exports": {
Expand All @@ -27,7 +27,7 @@
"@aptos-labs/ts-sdk": "^1.9.1",
"@aptos-labs/wallet-standard": "^0.0.11",
"@nightlylabs/nightly-connect-aptos": "0.0.5",
"@nightlylabs/wallet-selector-base": "0.4.2",
"@nightlylabs/wallet-selector-base": "0.4.3",
"@nightlylabs/nightly-connect-base": "^0.0.3",
"@wallet-standard/core": "^1.0.3",
"eventemitter3": "^5.0.1"
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-base",
"version": "0.4.2",
"version": "0.4.3",
"description": "",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"license": "ISC",
"dependencies": {
"@nightlylabs/nightly-connect-solana": "^0.0.3",
"@nightlylabs/wallet-selector-base": "^0.4.2",
"@nightlylabs/wallet-selector-base": "^0.4.3",
"@solana/wallet-adapter-base": "^0.9.22",
"@solana/wallet-standard": "^1.0.2",
"@solana/web3.js": "^1.77.2",
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/solana/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AppSolana extends EventEmitter<SolanaAppEvents> {

changeNetwork = async (input: SolanaChangeNetworkInput) => {
const changeNetworkResponse = await this.base.changeNetwork({
url: input.genesisHash,
url: input.url,
id: input.genesisHash
})
return {
Expand Down
1 change: 1 addition & 0 deletions sdk/packages/solana/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('Base Client tests', () => {
genesisHash: 'abcdefgh'
}
const _changedNetwork = await app.changeNetwork(newNetwork)
assert(_changedNetwork.success)
})
test('#getPendingRequests()', async () => {
client.removeListener('signTransactions')
Expand Down
43 changes: 41 additions & 2 deletions sdk/packages/solana/src/http-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe('Base Client tests', () => {
})
test('#resolveChangeNetwork()', async () => {
const newNetwork: SolanaChangeNetworkInput = {
genesisHash: 'abcdefgh'
genesisHash: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d',
url: 'https://solana-mainnet.rpc.extrnode.com/85c27167-63a1-4fa3-9971-fc1df7b132dc'
}

const _changedNetwork = app.changeNetwork(newNetwork)
Expand All @@ -84,7 +85,12 @@ describe('Base Client tests', () => {
await client.getPendingRequests({ sessionId: app.sessionId })
)[0] as ChangeNetworkSolanaRequest
expect(pendingRequest.type).toBe(ContentType.ChangeNetwork)
expect(pendingRequest.newNetwork.genesisHash).toBe('abcdefgh')
expect(pendingRequest.newNetwork.genesisHash).toBe(
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d'
)
expect(pendingRequest.newNetwork.url).toBe(
'https://solana-mainnet.rpc.extrnode.com/85c27167-63a1-4fa3-9971-fc1df7b132dc'
)

const payload = pendingRequest.newNetwork

Expand All @@ -93,5 +99,38 @@ describe('Base Client tests', () => {
sessionId: app.sessionId,
newNetwork: payload
})

await smartDelay()
const isSuccess = (await _changedNetwork).success
assert(isSuccess)
})
test('#rejectRequest()', async () => {
try {
const newNetwork: SolanaChangeNetworkInput = {
genesisHash: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d',
url: 'https://solana-mainnet.rpc.extrnode.com/85c27167-63a1-4fa3-9971-fc1df7b132dc'
}

// eslint-disable-next-line no-async-promise-executor
const promiseChangeNetwork = new Promise<void>(async (resolve) => {
expect(() => app.changeNetwork(newNetwork)).rejects.toThrow('test-error')
resolve()
})
await smartDelay()

const pendingRequest = (
await client.getPendingRequests({ sessionId: app.sessionId })
)[0] as ChangeNetworkSolanaRequest

await client.rejectRequest({
requestId: pendingRequest.requestId,
sessionId: app.sessionId,
reason: 'test-error'
})
await smartDelay()
await promiseChangeNetwork
} catch (error) {
console.log(error)
}
})
})
8 changes: 4 additions & 4 deletions sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8736559

Please sign in to comment.