-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.test.ts
94 lines (77 loc) · 3.54 KB
/
api.test.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
86
87
88
89
90
91
92
93
94
import { describe, it, expect } from 'vitest'
import { ApiClient } from './api.js'
import { sepolia } from 'viem/chains'
import { TEST_ADDRESS, EXAMPLE_SAFE_ADDRESS, EXAMPLE_SAFE } from '../tests/constants.js'
import { EXAMPLE_SAFE_INFO_RESPONSE, MULTISIG_TRANSACTION_TEST_RESPONSE_0, MULTISIG_TRANSACTION_TEST_RESPONSE_1, NONCE_0, TEST_TRANSACTION_HASH_0 } from '../tests/test-data.js'
describe('ApiClient', () => {
it('initializes properly', () => {
const api = new ApiClient({ url: 'http://localhost:8080', chainId: 1, safeAddress: EXAMPLE_SAFE })
expect(api.safeAddress).toEqual(EXAMPLE_SAFE)
expect(api.chainId).toEqual(1)
})
describe('getSafeInfo', () => {
it('should return the safe info', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getSafeInfo(EXAMPLE_SAFE)
expect(result).toEqual(EXAMPLE_SAFE_INFO_RESPONSE)
})
})
describe('getTransaction', () => {
it('should return a transaction for a given tx hash', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getTransaction(TEST_TRANSACTION_HASH_0)
expect(result).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE_0)
})
})
describe.skip('getMultisigTransactions', () => {
it('should return a list of transactions for a given safe address', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getMultisigTransactions(EXAMPLE_SAFE)
const firstTx = result?.results.find(tx => tx.nonce == NONCE_0)
expect(firstTx).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE_0)
})
})
describe.skip('getPendingTransactions', () => {
it('should return a list of pending transactions', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getPendingTransactions({ safeAddress: EXAMPLE_SAFE })
expect(result).toEqual(
{
count: 1,
next: null,
previous: null,
results: [MULTISIG_TRANSACTION_TEST_RESPONSE_1],
countUniqueNonce: 2,
})
})
})
describe('getDelegates', () => {
it('should list all delegates', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: 'sep:0x4bCdCa2D6fa461Af5c326a3124C1F8b6e3D11538' })
const result = await api.getDelegates()
expect(result).toEqual(
{
count: 1,
next: null,
previous: null,
results: [
{
delegate: '0x972A34a8A7B9E19DA849921F8d9D58F3D2DF568b',
delegator: '0xD3B282e9880cDcB1142830731cD83f7ac0e1043f',
expiryDate: null,
label: 'Delegate #1',
safe: '0x4bCdCa2D6fa461Af5c326a3124C1F8b6e3D11538',
},
],
},
)
})
})
describe('getSafesByOwner', () => {
it('should list all safes owned by an address', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getSafesByOwner(TEST_ADDRESS)
expect(result.safes).includes(EXAMPLE_SAFE_ADDRESS)
})
})
})