-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract-idlwrite-tx.ts
56 lines (48 loc) · 1.68 KB
/
extract-idlwrite-tx.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
import test from 'node:test'
import spok from 'spok'
import { getTransaction } from './utils/'
import { deserializeWriteTxData, extractIdlWriteTxData } from '../src/mudlands'
import { idlAddrForProgram } from '../src/utils'
import assert from 'assert/strict'
const USD = '1USDCmv8QmvZ9JaL7bmevGsNHn7ez8TNahJzCN551sb'
const FOO = '7w4ooixh9TFgfmcCUsDJzHd9QqDKyxz4Mq1Bke6PVXaY'
test('extract-idlwrite-tx: valid write transaction from local', async (t) => {
const idlAddr = await idlAddrForProgram(FOO)
const { transaction } = getTransaction('idl-write.foo-mini')
const buf = await extractIdlWriteTxData(transaction, FOO, idlAddr.toBase58())
assert(buf != null)
const json = await deserializeWriteTxData([buf])
assert(json != null)
const res = JSON.parse(json.toString())
spok(t, res, {
$topic: 'minimal idl',
version: '255',
name: 'foo',
instructions: [],
})
})
test('extract-idlwrite-tx: valid write transaction from mainnet', async (t) => {
const tgtAddr = '3s1nymBqKjEhftgQJhxktXLvTn9whxdLu2QV6hR6b29V'
let buf1: Buffer | null
let buf2: Buffer | null
{
const { transaction } = getTransaction('idl-write.usd-01')
buf1 = await extractIdlWriteTxData(transaction, USD, tgtAddr)
assert(buf1 != null)
}
{
const { transaction } = getTransaction('idl-write.usd-02')
buf2 = await extractIdlWriteTxData(transaction, USD, tgtAddr)
assert(buf2 != null)
}
const json = await deserializeWriteTxData([buf1, buf2])
assert(json != null)
const res = JSON.parse(json.toString())
spok(t, res, {
$topic: 'usd idl',
version: '1.11.0',
name: 'collateral_manager',
accounts: spok.arrayElements(6),
types: spok.arrayElements(4),
})
})