@@ -2,6 +2,7 @@ import { type ThirdwebContract, getContract } from "src/contract/contract.js";
2
2
import { getBalance } from "src/extensions/erc20/read/getBalance.js" ;
3
3
import { approve } from "src/extensions/erc20/write/approve.js" ;
4
4
import { sendAndConfirmTransaction } from "src/transaction/actions/send-and-confirm-transaction.js" ;
5
+ import { toUnits } from "src/utils/units.js" ;
5
6
import { beforeAll , describe , expect , it } from "vitest" ;
6
7
import { ANVIL_CHAIN } from "../../test/src/chains.js" ;
7
8
import { TEST_CLIENT } from "../../test/src/test-clients.js" ;
@@ -15,92 +16,101 @@ import { createTokenByImplConfig } from "./create-token-by-impl-config.js";
15
16
import { distributeToken } from "./distribute-token.js" ;
16
17
import { getDeployedEntrypointERC20 } from "./get-entrypoint-erc20.js" ;
17
18
18
- describe . runIf ( process . env . TW_SECRET_KEY ) ( "create token by impl config" , ( ) => {
19
- let token : ThirdwebContract ;
20
- beforeAll ( async ( ) => {
21
- // create token
22
- const tokenAddress = await createTokenByImplConfig ( {
23
- chain : ANVIL_CHAIN ,
24
- client : TEST_CLIENT ,
25
- account : TEST_ACCOUNT_A ,
26
- params : {
27
- name : "Test" ,
28
- maxSupply : 10_000_000_000n ,
29
- } ,
30
- salt : "salt123" ,
31
- } ) ;
19
+ describe . runIf ( process . env . TW_SECRET_KEY ) (
20
+ "create token by impl config" ,
21
+ {
22
+ timeout : 20000 ,
23
+ } ,
24
+ ( ) => {
25
+ let token : ThirdwebContract ;
26
+ beforeAll ( async ( ) => {
27
+ // create token
28
+ const tokenAddress = await createTokenByImplConfig ( {
29
+ chain : ANVIL_CHAIN ,
30
+ client : TEST_CLIENT ,
31
+ account : TEST_ACCOUNT_A ,
32
+ params : {
33
+ name : "Test" ,
34
+ maxSupply : 10_000_000_000n ,
35
+ } ,
36
+ salt : "salt123" ,
37
+ } ) ;
32
38
33
- token = getContract ( {
34
- address : tokenAddress ,
35
- client : TEST_CLIENT ,
36
- chain : ANVIL_CHAIN ,
37
- } ) ;
39
+ token = getContract ( {
40
+ address : tokenAddress ,
41
+ client : TEST_CLIENT ,
42
+ chain : ANVIL_CHAIN ,
43
+ } ) ;
38
44
39
- // approve tokens to entrypoint for distribution
40
- const entrypoint = await getDeployedEntrypointERC20 ( {
41
- chain : ANVIL_CHAIN ,
42
- client : TEST_CLIENT ,
43
- } ) ;
45
+ // approve tokens to entrypoint for distribution
46
+ const entrypoint = await getDeployedEntrypointERC20 ( {
47
+ chain : ANVIL_CHAIN ,
48
+ client : TEST_CLIENT ,
49
+ } ) ;
44
50
45
- const approvalTx = approve ( {
46
- contract : token ,
47
- spender : entrypoint ?. address as string ,
48
- amountWei : 1000n ,
49
- } ) ;
50
- await sendAndConfirmTransaction ( {
51
- transaction : approvalTx ,
52
- account : TEST_ACCOUNT_A ,
53
- } ) ;
54
- } ) ;
51
+ const approvalTx = approve ( {
52
+ contract : token ,
53
+ spender : entrypoint ?. address as string ,
54
+ amountWei : toUnits ( "1000" , 18 ) ,
55
+ } ) ;
56
+ await sendAndConfirmTransaction ( {
57
+ transaction : approvalTx ,
58
+ account : TEST_ACCOUNT_A ,
59
+ } ) ;
60
+ } , 20000 ) ;
55
61
56
- it ( "should distrbute tokens to specified recipients" , async ( ) => {
57
- const contents = [
58
- { recipient : TEST_ACCOUNT_B . address , amount : 10n } ,
59
- { recipient : TEST_ACCOUNT_C . address , amount : 15n } ,
60
- { recipient : TEST_ACCOUNT_D . address , amount : 20n } ,
61
- ] ;
62
+ it ( "should distrbute tokens to specified recipients" , async ( ) => {
63
+ const contents = [
64
+ { recipient : TEST_ACCOUNT_B . address , amount : 10n } ,
65
+ { recipient : TEST_ACCOUNT_C . address , amount : 15n } ,
66
+ { recipient : TEST_ACCOUNT_D . address , amount : 20n } ,
67
+ ] ;
62
68
63
- await distributeToken ( {
64
- account : TEST_ACCOUNT_A ,
65
- client : TEST_CLIENT ,
66
- chain : ANVIL_CHAIN ,
67
- tokenAddress : token . address ,
68
- contents,
69
- } ) ;
69
+ const transaction = await distributeToken ( {
70
+ client : TEST_CLIENT ,
71
+ chain : ANVIL_CHAIN ,
72
+ tokenAddress : token . address ,
73
+ contents,
74
+ } ) ;
70
75
71
- const balanceB = (
72
- await getBalance ( {
73
- contract : token ,
74
- address : TEST_ACCOUNT_B . address ,
75
- } )
76
- ) . value ;
76
+ await sendAndConfirmTransaction ( { transaction, account : TEST_ACCOUNT_A } ) ;
77
77
78
- const balanceC = (
79
- await getBalance ( {
80
- contract : token ,
81
- address : TEST_ACCOUNT_C . address ,
82
- } )
83
- ) . value ;
78
+ const balanceB = (
79
+ await getBalance ( {
80
+ contract : token ,
81
+ address : TEST_ACCOUNT_B . address ,
82
+ } )
83
+ ) . value ;
84
84
85
- const balanceD = (
86
- await getBalance ( {
87
- contract : token ,
88
- address : TEST_ACCOUNT_D . address ,
89
- } )
90
- ) . value ;
85
+ const balanceC = (
86
+ await getBalance ( {
87
+ contract : token ,
88
+ address : TEST_ACCOUNT_C . address ,
89
+ } )
90
+ ) . value ;
91
91
92
- // admin balance
93
- const balanceA = (
94
- await getBalance ( {
95
- contract : token ,
96
- address : TEST_ACCOUNT_A . address ,
97
- } )
98
- ) . value ;
92
+ const balanceD = (
93
+ await getBalance ( {
94
+ contract : token ,
95
+ address : TEST_ACCOUNT_D . address ,
96
+ } )
97
+ ) . value ;
98
+
99
+ // admin balance
100
+ const balanceA = (
101
+ await getBalance ( {
102
+ contract : token ,
103
+ address : TEST_ACCOUNT_A . address ,
104
+ } )
105
+ ) . value ;
99
106
100
- expect ( balanceB ) . to . equal ( 10n ) ;
101
- expect ( balanceC ) . to . equal ( 15n ) ;
102
- expect ( balanceD ) . to . equal ( 20n ) ;
107
+ expect ( balanceB ) . to . equal ( toUnits ( "10" , 18 ) ) ;
108
+ expect ( balanceC ) . to . equal ( toUnits ( "15" , 18 ) ) ;
109
+ expect ( balanceD ) . to . equal ( toUnits ( "20" , 18 ) ) ;
103
110
104
- expect ( balanceA ) . to . equal ( 10_000_000_000n - balanceB - balanceC - balanceD ) ;
105
- } ) ;
106
- } ) ;
111
+ expect ( balanceA ) . to . equal (
112
+ toUnits ( "10000000000" , 18 ) - balanceB - balanceC - balanceD ,
113
+ ) ;
114
+ } ) ;
115
+ } ,
116
+ ) ;
0 commit comments