tempo.ts 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +2 -12
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import { beforeAll, describe, expect, test } from 'vitest'
|
|
3
|
-
import { rpcUrl } from '../../../test/config.js'
|
|
4
|
-
import { accounts, clientWithAccount } from '../../../test/viem/config.js'
|
|
5
|
-
import * as actions from './index.js'
|
|
6
|
-
|
|
7
|
-
const account = accounts[0]
|
|
8
|
-
const account2 = accounts[1]
|
|
9
|
-
const account3 = accounts[2]
|
|
10
|
-
|
|
11
|
-
describe('create', () => {
|
|
12
|
-
test('default', async () => {
|
|
13
|
-
// create whitelist policy
|
|
14
|
-
const { receipt, ...result } = await actions.policy.createSync(
|
|
15
|
-
clientWithAccount,
|
|
16
|
-
{
|
|
17
|
-
type: 'whitelist',
|
|
18
|
-
},
|
|
19
|
-
)
|
|
20
|
-
expect(receipt).toBeDefined()
|
|
21
|
-
expect(result).toMatchInlineSnapshot(`
|
|
22
|
-
{
|
|
23
|
-
"policyId": 2n,
|
|
24
|
-
"policyType": 0,
|
|
25
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
26
|
-
}
|
|
27
|
-
`)
|
|
28
|
-
|
|
29
|
-
const { policyId } = result
|
|
30
|
-
|
|
31
|
-
// verify policy was created
|
|
32
|
-
const data = await actions.policy.getData(clientWithAccount, {
|
|
33
|
-
policyId,
|
|
34
|
-
})
|
|
35
|
-
expect(data.admin).toBe(account.address)
|
|
36
|
-
expect(data.type).toBe('whitelist')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('behavior: blacklist', async () => {
|
|
40
|
-
// create blacklist policy
|
|
41
|
-
const { receipt: blacklistReceipt, ...blacklistResult } =
|
|
42
|
-
await actions.policy.createSync(clientWithAccount, {
|
|
43
|
-
type: 'blacklist',
|
|
44
|
-
})
|
|
45
|
-
expect(blacklistReceipt).toBeDefined()
|
|
46
|
-
expect(blacklistResult).toMatchInlineSnapshot(`
|
|
47
|
-
{
|
|
48
|
-
"policyId": 3n,
|
|
49
|
-
"policyType": 1,
|
|
50
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
51
|
-
}
|
|
52
|
-
`)
|
|
53
|
-
|
|
54
|
-
const { policyId } = blacklistResult
|
|
55
|
-
|
|
56
|
-
// verify policy was created
|
|
57
|
-
const data = await actions.policy.getData(clientWithAccount, {
|
|
58
|
-
policyId,
|
|
59
|
-
})
|
|
60
|
-
expect(data.admin).toBe(account.address)
|
|
61
|
-
expect(data.type).toBe('blacklist')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test.skip('behavior: with initial addresses', async () => {
|
|
65
|
-
// create policy with initial addresses
|
|
66
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
67
|
-
type: 'whitelist',
|
|
68
|
-
addresses: [account2.address, account3.address],
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// verify addresses are whitelisted
|
|
72
|
-
const isAuthorized2 = await actions.policy.isAuthorized(clientWithAccount, {
|
|
73
|
-
policyId,
|
|
74
|
-
user: account2.address,
|
|
75
|
-
})
|
|
76
|
-
expect(isAuthorized2).toBe(true)
|
|
77
|
-
|
|
78
|
-
const isAuthorized3 = await actions.policy.isAuthorized(clientWithAccount, {
|
|
79
|
-
policyId,
|
|
80
|
-
user: account3.address,
|
|
81
|
-
})
|
|
82
|
-
expect(isAuthorized3).toBe(true)
|
|
83
|
-
|
|
84
|
-
// verify other address is not whitelisted
|
|
85
|
-
const isAuthorized = await actions.policy.isAuthorized(clientWithAccount, {
|
|
86
|
-
policyId,
|
|
87
|
-
user: account.address,
|
|
88
|
-
})
|
|
89
|
-
expect(isAuthorized).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
describe('setAdmin', () => {
|
|
94
|
-
test('default', async () => {
|
|
95
|
-
// create policy
|
|
96
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
97
|
-
type: 'whitelist',
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
// set new admin
|
|
101
|
-
const { receipt: setAdminReceipt, ...setAdminResult } =
|
|
102
|
-
await actions.policy.setAdminSync(clientWithAccount, {
|
|
103
|
-
policyId,
|
|
104
|
-
admin: account2.address,
|
|
105
|
-
})
|
|
106
|
-
expect(setAdminReceipt).toBeDefined()
|
|
107
|
-
expect(setAdminResult).toMatchInlineSnapshot(`
|
|
108
|
-
{
|
|
109
|
-
"admin": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
110
|
-
"policyId": 4n,
|
|
111
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
112
|
-
}
|
|
113
|
-
`)
|
|
114
|
-
|
|
115
|
-
{
|
|
116
|
-
// verify new admin
|
|
117
|
-
const data = await actions.policy.getData(clientWithAccount, {
|
|
118
|
-
policyId,
|
|
119
|
-
})
|
|
120
|
-
expect(data.admin).toBe(account2.address)
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
describe('modifyWhitelist', () => {
|
|
126
|
-
test('default', async () => {
|
|
127
|
-
// create whitelist policy
|
|
128
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
129
|
-
type: 'whitelist',
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
// verify account2 is not authorized
|
|
134
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
135
|
-
clientWithAccount,
|
|
136
|
-
{
|
|
137
|
-
policyId,
|
|
138
|
-
user: account2.address,
|
|
139
|
-
},
|
|
140
|
-
)
|
|
141
|
-
expect(isAuthorized).toBe(false)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// add account2 to whitelist
|
|
145
|
-
const { receipt: addReceipt, ...addResult } =
|
|
146
|
-
await actions.policy.modifyWhitelistSync(clientWithAccount, {
|
|
147
|
-
policyId,
|
|
148
|
-
address: account2.address,
|
|
149
|
-
allowed: true,
|
|
150
|
-
})
|
|
151
|
-
expect(addReceipt).toBeDefined()
|
|
152
|
-
expect(addResult).toMatchInlineSnapshot(`
|
|
153
|
-
{
|
|
154
|
-
"account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
155
|
-
"allowed": true,
|
|
156
|
-
"policyId": 5n,
|
|
157
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
158
|
-
}
|
|
159
|
-
`)
|
|
160
|
-
|
|
161
|
-
{
|
|
162
|
-
// verify account2 is authorized
|
|
163
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
164
|
-
clientWithAccount,
|
|
165
|
-
{
|
|
166
|
-
policyId,
|
|
167
|
-
user: account2.address,
|
|
168
|
-
},
|
|
169
|
-
)
|
|
170
|
-
expect(isAuthorized).toBe(true)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// remove account2 from whitelist
|
|
174
|
-
const { receipt: removeReceipt, ...removeResult } =
|
|
175
|
-
await actions.policy.modifyWhitelistSync(clientWithAccount, {
|
|
176
|
-
policyId,
|
|
177
|
-
address: account2.address,
|
|
178
|
-
allowed: false,
|
|
179
|
-
})
|
|
180
|
-
expect(removeReceipt).toBeDefined()
|
|
181
|
-
expect(removeResult).toMatchInlineSnapshot(`
|
|
182
|
-
{
|
|
183
|
-
"account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
184
|
-
"allowed": false,
|
|
185
|
-
"policyId": 5n,
|
|
186
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
187
|
-
}
|
|
188
|
-
`)
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
// verify account2 is no longer authorized
|
|
192
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
193
|
-
clientWithAccount,
|
|
194
|
-
{
|
|
195
|
-
policyId,
|
|
196
|
-
user: account2.address,
|
|
197
|
-
},
|
|
198
|
-
)
|
|
199
|
-
expect(isAuthorized).toBe(false)
|
|
200
|
-
}
|
|
201
|
-
})
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
describe('modifyBlacklist', () => {
|
|
205
|
-
test('default', async () => {
|
|
206
|
-
// create blacklist policy
|
|
207
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
208
|
-
type: 'blacklist',
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
{
|
|
212
|
-
// verify account2 is authorized (not blacklisted)
|
|
213
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
214
|
-
clientWithAccount,
|
|
215
|
-
{
|
|
216
|
-
policyId,
|
|
217
|
-
user: account2.address,
|
|
218
|
-
},
|
|
219
|
-
)
|
|
220
|
-
expect(isAuthorized).toBe(true)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// add account2 to blacklist
|
|
224
|
-
const { receipt: addBlacklistReceipt, ...addBlacklistResult } =
|
|
225
|
-
await actions.policy.modifyBlacklistSync(clientWithAccount, {
|
|
226
|
-
policyId,
|
|
227
|
-
address: account2.address,
|
|
228
|
-
restricted: true,
|
|
229
|
-
})
|
|
230
|
-
expect(addBlacklistReceipt).toBeDefined()
|
|
231
|
-
expect(addBlacklistResult).toMatchInlineSnapshot(`
|
|
232
|
-
{
|
|
233
|
-
"account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
234
|
-
"policyId": 6n,
|
|
235
|
-
"restricted": true,
|
|
236
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
237
|
-
}
|
|
238
|
-
`)
|
|
239
|
-
|
|
240
|
-
{
|
|
241
|
-
// verify account2 is not authorized (blacklisted)
|
|
242
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
243
|
-
clientWithAccount,
|
|
244
|
-
{
|
|
245
|
-
policyId,
|
|
246
|
-
user: account2.address,
|
|
247
|
-
},
|
|
248
|
-
)
|
|
249
|
-
expect(isAuthorized).toBe(false)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// remove account2 from blacklist
|
|
253
|
-
const { receipt: removeBlacklistReceipt, ...removeBlacklistResult } =
|
|
254
|
-
await actions.policy.modifyBlacklistSync(clientWithAccount, {
|
|
255
|
-
policyId,
|
|
256
|
-
address: account2.address,
|
|
257
|
-
restricted: false,
|
|
258
|
-
})
|
|
259
|
-
expect(removeBlacklistReceipt).toBeDefined()
|
|
260
|
-
expect(removeBlacklistResult).toMatchInlineSnapshot(`
|
|
261
|
-
{
|
|
262
|
-
"account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
263
|
-
"policyId": 6n,
|
|
264
|
-
"restricted": false,
|
|
265
|
-
"updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
266
|
-
}
|
|
267
|
-
`)
|
|
268
|
-
|
|
269
|
-
{
|
|
270
|
-
// verify account2 is authorized again
|
|
271
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
272
|
-
clientWithAccount,
|
|
273
|
-
{
|
|
274
|
-
policyId,
|
|
275
|
-
user: account2.address,
|
|
276
|
-
},
|
|
277
|
-
)
|
|
278
|
-
expect(isAuthorized).toBe(true)
|
|
279
|
-
}
|
|
280
|
-
})
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
describe('getData', () => {
|
|
284
|
-
test('default', async () => {
|
|
285
|
-
// create policy
|
|
286
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
287
|
-
type: 'whitelist',
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
{
|
|
291
|
-
// get policy data
|
|
292
|
-
const data = await actions.policy.getData(clientWithAccount, {
|
|
293
|
-
policyId,
|
|
294
|
-
})
|
|
295
|
-
expect(data.admin).toBe(account.address)
|
|
296
|
-
expect(data.type).toBe('whitelist')
|
|
297
|
-
}
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
test('behavior: blacklist', async () => {
|
|
301
|
-
// create blacklist policy
|
|
302
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
303
|
-
type: 'blacklist',
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
{
|
|
307
|
-
// get policy data
|
|
308
|
-
const data = await actions.policy.getData(clientWithAccount, {
|
|
309
|
-
policyId,
|
|
310
|
-
})
|
|
311
|
-
expect(data.admin).toBe(account.address)
|
|
312
|
-
expect(data.type).toBe('blacklist')
|
|
313
|
-
}
|
|
314
|
-
})
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
describe('isAuthorized', () => {
|
|
318
|
-
test('special policy: always-reject (policyId 0)', async () => {
|
|
319
|
-
const isAuthorized = await actions.policy.isAuthorized(clientWithAccount, {
|
|
320
|
-
policyId: 0n,
|
|
321
|
-
user: account.address,
|
|
322
|
-
})
|
|
323
|
-
expect(isAuthorized).toBe(false)
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
test('special policy: always-allow (policyId 1)', async () => {
|
|
327
|
-
const isAuthorized = await actions.policy.isAuthorized(clientWithAccount, {
|
|
328
|
-
policyId: 1n,
|
|
329
|
-
user: account.address,
|
|
330
|
-
})
|
|
331
|
-
expect(isAuthorized).toBe(true)
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
test.skip('whitelist policy', async () => {
|
|
335
|
-
// create whitelist policy
|
|
336
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
337
|
-
type: 'whitelist',
|
|
338
|
-
addresses: [account2.address],
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
{
|
|
342
|
-
// verify whitelisted address is authorized
|
|
343
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
344
|
-
clientWithAccount,
|
|
345
|
-
{
|
|
346
|
-
policyId,
|
|
347
|
-
user: account2.address,
|
|
348
|
-
},
|
|
349
|
-
)
|
|
350
|
-
expect(isAuthorized).toBe(true)
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
{
|
|
354
|
-
// verify non-whitelisted address is not authorized
|
|
355
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
356
|
-
clientWithAccount,
|
|
357
|
-
{
|
|
358
|
-
policyId,
|
|
359
|
-
user: account.address,
|
|
360
|
-
},
|
|
361
|
-
)
|
|
362
|
-
expect(isAuthorized).toBe(false)
|
|
363
|
-
}
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
test.skip('blacklist policy', async () => {
|
|
367
|
-
// create blacklist policy
|
|
368
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
369
|
-
type: 'blacklist',
|
|
370
|
-
addresses: [account2.address],
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
{
|
|
374
|
-
// verify blacklisted address is not authorized
|
|
375
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
376
|
-
clientWithAccount,
|
|
377
|
-
{
|
|
378
|
-
policyId,
|
|
379
|
-
user: account2.address,
|
|
380
|
-
},
|
|
381
|
-
)
|
|
382
|
-
expect(isAuthorized).toBe(false)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
{
|
|
386
|
-
// verify non-blacklisted address is authorized
|
|
387
|
-
const isAuthorized = await actions.policy.isAuthorized(
|
|
388
|
-
clientWithAccount,
|
|
389
|
-
{
|
|
390
|
-
policyId,
|
|
391
|
-
user: account.address,
|
|
392
|
-
},
|
|
393
|
-
)
|
|
394
|
-
expect(isAuthorized).toBe(true)
|
|
395
|
-
}
|
|
396
|
-
})
|
|
397
|
-
})
|
|
398
|
-
|
|
399
|
-
describe('watchCreate', () => {
|
|
400
|
-
test('default', async () => {
|
|
401
|
-
const logs: any[] = []
|
|
402
|
-
const unwatch = actions.policy.watchCreate(clientWithAccount, {
|
|
403
|
-
onPolicyCreated: (args, log) => {
|
|
404
|
-
logs.push({ args, log })
|
|
405
|
-
},
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
// create policy
|
|
409
|
-
await actions.policy.createSync(clientWithAccount, {
|
|
410
|
-
type: 'whitelist',
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
await setTimeout(500)
|
|
414
|
-
unwatch()
|
|
415
|
-
|
|
416
|
-
expect(logs.length).toBe(1)
|
|
417
|
-
expect(logs[0].args.policyId).toBeDefined()
|
|
418
|
-
expect(logs[0].args.updater).toBe(account.address)
|
|
419
|
-
expect(logs[0].args.type).toBe('whitelist')
|
|
420
|
-
})
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
describe('watchAdminUpdated', () => {
|
|
424
|
-
beforeAll(async () => {
|
|
425
|
-
await fetch(`${rpcUrl}/restart`)
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
test('default', async () => {
|
|
429
|
-
// create policy
|
|
430
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
431
|
-
type: 'whitelist',
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
const logs: any[] = []
|
|
435
|
-
const unwatch = actions.policy.watchAdminUpdated(clientWithAccount, {
|
|
436
|
-
onAdminUpdated: (args, log) => {
|
|
437
|
-
logs.push({ args, log })
|
|
438
|
-
},
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
// set new admin
|
|
442
|
-
await actions.policy.setAdminSync(clientWithAccount, {
|
|
443
|
-
policyId,
|
|
444
|
-
admin: account2.address,
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
await setTimeout(500)
|
|
448
|
-
unwatch()
|
|
449
|
-
|
|
450
|
-
expect(logs[0].args.policyId).toBeDefined()
|
|
451
|
-
expect(logs[0].args.updater).toBe(account.address)
|
|
452
|
-
expect(logs[0].args.admin).toBe(account2.address)
|
|
453
|
-
})
|
|
454
|
-
})
|
|
455
|
-
|
|
456
|
-
describe('watchWhitelistUpdated', () => {
|
|
457
|
-
test('default', async () => {
|
|
458
|
-
// create whitelist policy
|
|
459
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
460
|
-
type: 'whitelist',
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
const logs: any[] = []
|
|
464
|
-
const unwatch = actions.policy.watchWhitelistUpdated(clientWithAccount, {
|
|
465
|
-
onWhitelistUpdated: (args, log) => {
|
|
466
|
-
logs.push({ args, log })
|
|
467
|
-
},
|
|
468
|
-
})
|
|
469
|
-
|
|
470
|
-
// add address to whitelist
|
|
471
|
-
await actions.policy.modifyWhitelistSync(clientWithAccount, {
|
|
472
|
-
policyId,
|
|
473
|
-
address: account2.address,
|
|
474
|
-
allowed: true,
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
// remove address from whitelist
|
|
478
|
-
await actions.policy.modifyWhitelistSync(clientWithAccount, {
|
|
479
|
-
policyId,
|
|
480
|
-
address: account2.address,
|
|
481
|
-
allowed: false,
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
await setTimeout(500)
|
|
485
|
-
unwatch()
|
|
486
|
-
|
|
487
|
-
expect(logs.length).toBe(2)
|
|
488
|
-
expect(logs[0].args.policyId).toBeDefined()
|
|
489
|
-
expect(logs[0].args.updater).toBe(account.address)
|
|
490
|
-
expect(logs[0].args.account).toBe(account2.address)
|
|
491
|
-
expect(logs[0].args.allowed).toBe(true)
|
|
492
|
-
expect(logs[1].args.allowed).toBe(false)
|
|
493
|
-
})
|
|
494
|
-
})
|
|
495
|
-
|
|
496
|
-
describe('watchBlacklistUpdated', () => {
|
|
497
|
-
test('default', async () => {
|
|
498
|
-
// create blacklist policy
|
|
499
|
-
const { policyId } = await actions.policy.createSync(clientWithAccount, {
|
|
500
|
-
type: 'blacklist',
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
const logs: any[] = []
|
|
504
|
-
const unwatch = actions.policy.watchBlacklistUpdated(clientWithAccount, {
|
|
505
|
-
onBlacklistUpdated: (args, log) => {
|
|
506
|
-
logs.push({ args, log })
|
|
507
|
-
},
|
|
508
|
-
})
|
|
509
|
-
|
|
510
|
-
// add address to blacklist
|
|
511
|
-
await actions.policy.modifyBlacklistSync(clientWithAccount, {
|
|
512
|
-
policyId,
|
|
513
|
-
address: account2.address,
|
|
514
|
-
restricted: true,
|
|
515
|
-
})
|
|
516
|
-
|
|
517
|
-
// remove address from blacklist
|
|
518
|
-
await actions.policy.modifyBlacklistSync(clientWithAccount, {
|
|
519
|
-
policyId,
|
|
520
|
-
address: account2.address,
|
|
521
|
-
restricted: false,
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
await setTimeout(500)
|
|
525
|
-
unwatch()
|
|
526
|
-
|
|
527
|
-
expect(logs.length).toBe(2)
|
|
528
|
-
expect(logs[0].args.policyId).toBeDefined()
|
|
529
|
-
expect(logs[0].args.updater).toBe(account.address)
|
|
530
|
-
expect(logs[0].args.account).toBe(account2.address)
|
|
531
|
-
expect(logs[0].args.restricted).toBe(true)
|
|
532
|
-
expect(logs[1].args.restricted).toBe(false)
|
|
533
|
-
})
|
|
534
|
-
})
|