Skip to content

Commit

Permalink
updating tests based on ecosystems changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1asm committed Mar 26, 2024
1 parent a79c52c commit 052ca1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 90 deletions.
2 changes: 1 addition & 1 deletion frontend/integration/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function handlerAmountAndProof(
} else {
res.status(200).json({
amount: result.amount,
proof: result.proof,
proof: result.proof_of_inclusion,
address: identity,
})
}
Expand Down
92 changes: 12 additions & 80 deletions frontend/integration/integrationTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,8 @@ import { ethers } from 'ethers'
import {
addTestWalletsToDatabase as addTestWalletsToInMemoryDb,
clearInMemoryDb,
getInMemoryDb,
} from './utils'

function getDatabasePool() {
return {
end: async () => {},
}
}

async function clearDatabase(..._: any[]) {}

async function addTestWalletsToDatabase(..._: any[]) {
return []
}

const pool = getDatabasePool()

describe('integration test', () => {
let root: Buffer
let maxAmount: anchor.BN
Expand Down Expand Up @@ -241,7 +226,7 @@ describe('integration test', () => {
).toBeTruthy()
}, 40000)

it('submits a cosmwasm claim', async () => {
it('submits a terra claim', async () => {
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
'terra',
testWallets.terra[0].address()
Expand Down Expand Up @@ -274,7 +259,7 @@ describe('integration test', () => {
const claimantFund = await mint.getAccountInfo(claimantFundPubkey)

expect(
claimantFund.amount.eq(new anchor.BN(3000000 + 6000000))
claimantFund.amount.eq(new anchor.BN(3000000 + 7000000))
).toBeTruthy()

const { txnEvents } =
Expand All @@ -301,7 +286,7 @@ describe('integration test', () => {

it('submits multiple claims at once', async () => {
const wallets = {
terra: testWallets.terra[0],
injective: testWallets.injective[0],
osmosis: testWallets.osmosis[0],
}

Expand Down Expand Up @@ -360,50 +345,11 @@ describe('integration test', () => {

expect(
claimantFund.amount.eq(
new anchor.BN(3000000 + 6000000 + 6100000 + 6200000)
new anchor.BN(3000000 + 7000000 + 8000000 + 9000000)
)
).toBeTruthy()
})

it('submits an injective claim', async () => {
const wallet = testWallets.injective[0]
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
'injective',
wallet.address()
))!
const signedMessage = await wallet.signMessage(
tokenDispenserProvider.generateAuthorizationPayload()
)

await Promise.all(
await tokenDispenserProvider.submitClaims(
[
{
claimInfo,
proofOfInclusion,
signedMessage,
},
],
mockfetchFundTransaction
)
)

expect(
await tokenDispenserProvider.isClaimAlreadySubmitted(claimInfo)
).toBeTruthy()

const claimantFundPubkey =
await tokenDispenserProvider.getClaimantFundAddress()

const claimantFund = await mint.getAccountInfo(claimantFundPubkey)

expect(
claimantFund.amount.eq(
new anchor.BN(3000000 + 6000000 + 6100000 + 6200000 + 7000000)
)
).toBeTruthy()
}, 40000)

it('submits an aptos claim', async () => {
const wallet = testWallets.aptos[0]
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
Expand Down Expand Up @@ -438,9 +384,7 @@ describe('integration test', () => {

expect(
claimantFund.amount.eq(
new anchor.BN(
3000000 + 6000000 + 6100000 + 6200000 + 7000000 + 5000000
)
new anchor.BN(3000000 + 7000000 + 8000000 + 9000000 + 6000000)
)
).toBeTruthy()
})
Expand Down Expand Up @@ -484,13 +428,7 @@ describe('integration test', () => {
expect(
claimantFund.amount.eq(
new anchor.BN(
3000000 +
6000000 +
6100000 +
6200000 +
7000000 +
5000000 +
1000000
3000000 + 7000000 + 8000000 + 9000000 + 6000000 + 1000000
)
)
).toBeTruthy()
Expand Down Expand Up @@ -530,14 +468,7 @@ describe('integration test', () => {
expect(
claimantFund.amount.eq(
new anchor.BN(
3000000 +
6000000 +
6100000 +
6200000 +
7000000 +
5000000 +
1000000 +
2000000
3000000 + 7000000 + 8000000 + 9000000 + 6000000 + 1000000 + 2000000
)
)
).toBeTruthy()
Expand Down Expand Up @@ -579,18 +510,18 @@ describe('integration test', () => {
claimantFund.amount.eq(
new anchor.BN(
3000000 +
6000000 +
6100000 +
6200000 +
7000000 +
5000000 +
8000000 +
9000000 +
6000000 +
1000000 +
2000000 +
4000000
)
)
).toBeTruthy()
}, 40000)

it('fails to submit a duplicate claim', async () => {
const wallet = testWallets.sui[0]
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
Expand All @@ -615,6 +546,7 @@ describe('integration test', () => {
)
expect(JSON.stringify(res[0]).includes('InstructionError')).toBeTruthy()
})

it('eventSubscriber parses error transaction logs', async () => {
const { txnEvents, failedTxnInfos } =
await tokenDispenserEventSubscriber.parseTransactionLogs()
Expand Down
9 changes: 2 additions & 7 deletions frontend/integration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import 'dotenv/config' // Load environment variables from .env file
import * as anchor from '@coral-xyz/anchor'
import {
TestEvmWallet,
TestSolanaWallet,
TestWallet,
} from '../claim_sdk/testWallets'
import { TestWallet } from '../claim_sdk/testWallets'
import { ClaimInfo, Ecosystem, Ecosystems } from '../claim_sdk/claim'
import { getMaxAmount } from '../claim_sdk/claim'
import { MerkleTree } from '../claim_sdk/merkleTree'

const CHUNK_SIZE = 1000
const SOLANA_ECOSYSTEM_INDEX = 2
const EVM_ECOSYSTEM_INDEX = 3

export const EVM_CHAINS = [
'optimism-mainnet',
'arbitrum-mainnet',
Expand Down
4 changes: 2 additions & 2 deletions frontend/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export function handleAmountAndProofResponse(
ecosystem: Ecosystem,
identity: string,
status: number,
{ address, amount, hashes }: any = {}
{ address, amount, proof }: any = {}
): { claimInfo: ClaimInfo; proofOfInclusion: Uint8Array[] } | undefined {
if (status == 404) return undefined
if (status == 200) {
if (identity === address) {
return {
claimInfo: new ClaimInfo(ecosystem, identity, new BN(amount)),
proofOfInclusion: parseProof(hashes),
proofOfInclusion: parseProof(proof),
}
}
}
Expand Down

0 comments on commit 052ca1c

Please sign in to comment.