-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindexer-lookup.spec.ts
85 lines (70 loc) · 3.4 KB
/
indexer-lookup.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Address } from 'algosdk'
import { beforeEach, describe, expect, test } from 'vitest'
import { getTestingAppContract } from '../tests/example-contracts/testing-app/contract'
import * as indexer from './indexer-lookup'
import { algorandFixture, runWhenIndexerCaughtUp } from './testing'
import { AlgoAmount } from './types/amount'
describe('indexer-lookup', () => {
const localnet = algorandFixture()
beforeEach(localnet.newScope, 10_000)
const sendTestTransaction = async (amount?: AlgoAmount, from?: Address) => {
return await localnet.context.algorand.send.payment({
sender: from ?? localnet.context.testAccount,
receiver: localnet.context.testAccount,
amount: amount ?? (1).microAlgo(),
})
}
test('Transaction is found by id', async () => {
const { algorand, waitForIndexer } = localnet.context
const { transaction } = await sendTestTransaction()
await waitForIndexer()
const txn = await algorand.client.indexer.lookupTransactionByID(transaction.txID()).do()
expect(txn.transaction.id).toBe(transaction.txID())
expect(txn.currentRound).toBeGreaterThanOrEqual(transaction.firstValid)
}, 20_000)
test('Account is found by id', async () => {
const { algorand, testAccount } = localnet.context
await runWhenIndexerCaughtUp(() => algorand.client.indexer.lookupAccountByID(testAccount.addr).do())
const account = await algorand.client.indexer.lookupAccountByID(testAccount.addr).do()
expect(account.account.address).toBe(testAccount.addr.toString())
}, 20_000)
test('Transactions are searched with pagination', async () => {
const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context
const secondAccount = await generateAccount({
initialFunds: (1).algo(),
suppressLog: true,
})
const { transaction: transaction1 } = await sendTestTransaction((1).microAlgo())
const { transaction: transaction2 } = await sendTestTransaction((2).microAlgo())
await sendTestTransaction((1).microAlgo(), secondAccount)
await waitForIndexer()
const transactions = await indexer.searchTransactions(
algorand.client.indexer,
(s) => s.txType('pay').addressRole('sender').address(testAccount),
1,
)
expect(transactions.currentRound).toBeGreaterThan(0n)
expect(transactions.transactions.map((t) => t.id).sort()).toEqual([transaction1.txID(), transaction2.txID()].sort())
}, 20_000)
test('Application create transactions are found by creator with pagination', async () => {
const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context
const secondAccount = await generateAccount({
initialFunds: (1).algo(),
suppressLog: true,
})
const app = await getTestingAppContract()
const factory = algorand.client.getAppFactory({
appSpec: app.appSpec,
defaultSender: testAccount,
deletable: false,
updatable: false,
deployTimeParams: { VALUE: 1 },
})
const { result: app1 } = await factory.send.bare.create()
const { result: app2 } = await factory.send.bare.create({ deployTimeParams: { VALUE: 2 } })
await factory.send.bare.create({ sender: secondAccount })
await waitForIndexer()
const apps = await indexer.lookupAccountCreatedApplicationByAddress(algorand.client.indexer, testAccount, true, 1)
expect(apps.map((a) => BigInt(a.id)).sort()).toEqual([app1.appId, app2.appId].sort())
}, 20_000)
})