Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/add-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1asm committed Mar 25, 2024
2 parents bacee8f + 3e521a1 commit 97fd1e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
26 changes: 10 additions & 16 deletions frontend/integration/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
import { ClaimInfo, Ecosystem } from '../claim_sdk/claim'
import { loadFunderWallet } from '../claim_sdk/testWallets'
import { checkTransactions } from '../utils/verifyTransaction'
import fs from 'fs'
import path from 'path'
import { getInMemoryDb } from './utils'

//import handlerAmountAndProof from '../pages/api/grant/v1/amount_and_proof'
//import handlerFundTransaction from '../pages/api/grant/v1/fund_transaction'
Expand All @@ -41,13 +44,6 @@ function getAmountAndProofRoute(..._: any[]): string {
return ''
}

function lowerCapIfEvm(identity: string, ecosystem: string): string {
if (ecosystem === 'evm') {
return identity.toLowerCase()
}
return identity
}

export async function handlerAmountAndProof(
req: NextApiRequest,
res: NextApiResponse
Expand All @@ -66,20 +62,18 @@ export async function handlerAmountAndProof(
}

try {
const result = {
rows: [{ amount: 0, proof_of_inclusion: Buffer.from('') }],
} /*await pool.query(
'SELECT amount, proof_of_inclusion FROM claims WHERE ecosystem = $1 AND identity = $2',
[ecosystem, lowerCapIfEvm(identity, ecosystem)]
)*/
if (result.rows.length == 0) {
// TODO: read flat file?
const db = getInMemoryDb()
const result = db.get(ecosystem)!.get(identity)
if (!result) {
res.status(404).json({
error: `No result found for ${ecosystem} identity ${identity}`,
})
} else {
res.status(200).json({
amount: result.rows[0].amount,
proof: (result.rows[0].proof_of_inclusion as Buffer).toString('hex'),
amount: result.amount,
proof: result.proof,
address: identity,
})
}
} catch (error) {
Expand Down
19 changes: 13 additions & 6 deletions frontend/integration/integrationTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ describe('integration test', () => {
})

it('submits an evm claim', async () => {
const { claimInfo, proofOfInclusion } = getInMemoryDb()
.get('evm')
.get(testWallets.evm[0].address())
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
'evm',
testWallets.evm[0].address()
))!

const signedMessage = await testWallets.evm[0].signMessage(
tokenDispenserProvider.generateAuthorizationPayload()
Expand Down Expand Up @@ -299,12 +300,18 @@ describe('integration test', () => {
}, 40000)

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

const claims = await Promise.all(
wallets.map(async (wallet) => {
Object.entries(wallets).map(async ([ecosystem, wallet]) => {
const { claimInfo, proofOfInclusion } =
(await mockFetchAmountAndProof('terra', wallet.address()))!
(await mockFetchAmountAndProof(
ecosystem as Ecosystem,
wallet.address()
))!
return {
claimInfo,
proofOfInclusion,
Expand Down
7 changes: 4 additions & 3 deletions frontend/integration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export type SolanaBreakdownRow = {
amount: anchor.BN
}

const DB = new Map<any, any>()
type InMemoryDB = Map<string, Map<string, any>>
const DB: InMemoryDB = new Map()

/** Get in memory db. */
export function getInMemoryDb(): Map<any, any> {
export function getInMemoryDb(): InMemoryDB {
return DB
}

Expand Down Expand Up @@ -95,7 +96,7 @@ export function addClaimInfosToInMemoryDb(claimInfos: ClaimInfo[]): Buffer {
if (!DB.has(claimInfo.ecosystem)) {
DB.set(claimInfo.ecosystem, new Map<any, any>())
}
DB.get(claimInfo.ecosystem).set(claimInfo.identity, claimInfo)
DB.get(claimInfo.ecosystem)!.set(claimInfo.identity, claimInfo)
}
}
const claimsInsertEnd = Date.now()
Expand Down

0 comments on commit 97fd1e3

Please sign in to comment.