1- import { BigNumber } from '@ethersproject/bignumber' ;
2-
31import fs from 'fs' ;
2+
3+ import { addHexPrefix } from 'enc-utils' ;
4+
45import {
5- hashMessage ,
66 CompiledContract ,
77 Contract ,
88 deployContract ,
9- JsonParser ,
10- waitForTx ,
11- randomAddress ,
12- getSelectorFromName ,
13- ensure0x ,
14- getStarkKey ,
159 getKeyPair ,
10+ getStarkKey ,
11+ hashMessage ,
1612 sign ,
13+ utils ,
14+ waitForTx ,
1715} from '../src' ;
16+ import { toBN } from '../src/utils/number' ;
17+
18+ const {
19+ json : { parse } ,
20+ starknet : { getSelectorFromName, randomAddress } ,
21+ number : { toHex } ,
22+ } = utils ;
1823
1924describe ( 'getStarkAccountFromPk()' , ( ) => {
2025 test ( 'it works with valid pk' , ( ) => {
@@ -35,10 +40,10 @@ describe('getStarkAccountFromPk()', () => {
3540 } ) ;
3641} ) ;
3742
38- const compiledArgentAccount : CompiledContract = JsonParser . parse (
43+ const compiledArgentAccount : CompiledContract = parse (
3944 fs . readFileSync ( './__mocks__/ArgentAccount.json' ) . toString ( 'ascii' )
4045) ;
41- const compiledErc20 : CompiledContract = JsonParser . parse (
46+ const compiledErc20 : CompiledContract = parse (
4247 fs . readFileSync ( './__mocks__/ERC20.json' ) . toString ( 'ascii' )
4348) ;
4449
@@ -93,18 +98,18 @@ describe('deploy and test Wallet', () => {
9398 test ( 'read nonce' , async ( ) => {
9499 const { nonce } = await wallet . call ( 'get_current_nonce' ) ;
95100
96- expect ( BigNumber . from ( nonce ) ) . toStrictEqual ( BigNumber . from ( 0 ) ) ;
101+ expect ( toBN ( nonce as string ) . toString ( ) ) . toStrictEqual ( toBN ( 0 ) . toString ( ) ) ;
97102 } ) ;
98103 test ( 'read balance of wallet' , async ( ) => {
99104 const { res } = await erc20 . call ( 'balance_of' , {
100105 user : walletAddress ,
101106 } ) ;
102107
103- expect ( BigNumber . from ( res ) ) . toStrictEqual ( BigNumber . from ( 1000 ) ) ;
108+ expect ( toBN ( res as string ) . toString ( ) ) . toStrictEqual ( toBN ( 1000 ) . toString ( ) ) ;
104109 } ) ;
105110 test ( 'execute by wallet owner' , async ( ) => {
106111 const { nonce } = await wallet . call ( 'get_current_nonce' ) ;
107- const msgHash = ensure0x (
112+ const msgHash = addHexPrefix (
108113 hashMessage (
109114 walletAddress ,
110115 erc20Address ,
@@ -113,14 +118,14 @@ describe('deploy and test Wallet', () => {
113118 nonce . toString ( )
114119 )
115120 ) ;
116- console . log ( msgHash ) ;
121+
117122 const { r, s } = sign ( starkKeyPair , msgHash ) ;
118123 const { code, tx_id } = await wallet . invoke ( 'execute' , {
119124 to : erc20Address ,
120125 selector : getSelectorFromName ( 'transfer' ) ,
121126 calldata : [ erc20Address , '10' ] ,
122127 nonce : nonce . toString ( ) ,
123- sig : [ ensure0x ( r . toString ( 'hex' ) ) , ensure0x ( s . toString ( 'hex' ) ) ] ,
128+ sig : [ toHex ( r ) , toHex ( s ) ] ,
124129 } ) ;
125130
126131 // I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
@@ -135,7 +140,7 @@ describe('deploy and test Wallet', () => {
135140 user : walletAddress ,
136141 } ) ;
137142
138- expect ( BigNumber . from ( res ) ) . toStrictEqual ( BigNumber . from ( 990 ) ) ;
143+ expect ( toBN ( res as string ) . toString ( ) ) . toStrictEqual ( toBN ( 990 ) . toString ( ) ) ;
139144 } ) ;
140145} ) ;
141146
@@ -149,14 +154,12 @@ test('build tx', async () => {
149154 const selector = getSelectorFromName ( 'transfer' ) ;
150155
151156 expect ( selector ) . toBe (
152- BigNumber . from (
153- '232670485425082704932579856502088130646006032362877466777181098476241604910'
154- ) . toHexString ( )
157+ toHex ( toBN ( '232670485425082704932579856502088130646006032362877466777181098476241604910' ) )
155158 ) ;
156159
157160 const msgHash = hashMessage ( address , '1' , selector , [ '6' , '7' ] , '0' ) ;
158- expect ( BigNumber . from ( msgHash ) ) . toStrictEqual (
159- BigNumber . from ( '2221651675559331189881349481637314109810712322791057846116415219218634672652' )
161+ expect ( toBN ( msgHash ) . toString ( ) ) . toStrictEqual (
162+ toBN ( '2221651675559331189881349481637314109810712322791057846116415219218634672652' ) . toString ( )
160163 ) ;
161164
162165 const { r, s } = sign ( keyPair , msgHash ) ;
0 commit comments