@@ -15,15 +15,13 @@ contract("Exchange", (accounts: string[]) => {
1515 let ownerD : string ;
1616
1717 const createExchange = async ( setupTestState : boolean = true ) => {
18- exchangeID = await ctx . createExchange (
19- ctx . testContext . stateOwners [ 0 ] ,
20- { setupTestState}
21- ) ;
18+ exchangeID = await ctx . createExchange ( ctx . testContext . stateOwners [ 0 ] , {
19+ setupTestState
20+ } ) ;
2221 operatorAccountID = await ctx . getActiveOperator ( exchangeID ) ;
2322 operator = ctx . getAccount ( operatorAccountID ) . owner ;
2423 } ;
2524
26-
2725 before ( async ( ) => {
2826 ctx = new ExchangeTestUtil ( ) ;
2927 await ctx . initialize ( accounts ) ;
@@ -53,35 +51,80 @@ contract("Exchange", (accounts: string[]) => {
5351 await ctx . deposit ( ownerA , ownerA , token , balance ) ;
5452
5553 // Send some funds over to the new account
56- await ctx . transfer ( ownerA , ownerB , token , fee . mul ( new BN ( 10 ) ) , token , fee , { transferToNew : true } ) ;
54+ await ctx . transfer (
55+ ownerA ,
56+ ownerB ,
57+ token ,
58+ fee . mul ( new BN ( 10 ) ) ,
59+ token ,
60+ fee ,
61+ { transferToNew : true }
62+ ) ;
5763
5864 // Update the key pair of the new account
5965 let newKeyPair = ctx . getKeyPairEDDSA ( ) ;
60- await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , { authMethod : AuthMethod . ECDSA } ) ;
66+ await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , {
67+ authMethod : AuthMethod . ECDSA
68+ } ) ;
6169
6270 // Update the key pair of the new account again to disable EdDSA signatures
63- await ctx . requestAccountUpdate ( ownerB , token , fee , ctx . getZeroKeyPairEDDSA ( ) ) ;
71+ await ctx . requestAccountUpdate (
72+ ownerB ,
73+ token ,
74+ fee ,
75+ ctx . getZeroKeyPairEDDSA ( ) ,
76+ { maxFee : fee . mul ( new BN ( 3 ) ) }
77+ ) ;
6478
6579 // Transfer some funds using an ECDSA signature
66- await ctx . transfer ( ownerB , ownerA , token , fee . mul ( new BN ( 10 ) ) , token , fee , { authMethod : AuthMethod . ECDSA } ) ;
80+ await ctx . transfer (
81+ ownerB ,
82+ ownerA ,
83+ token ,
84+ fee . mul ( new BN ( 10 ) ) ,
85+ token ,
86+ fee ,
87+ { authMethod : AuthMethod . ECDSA }
88+ ) ;
6789
6890 // Enable EdDSA signature again
6991 newKeyPair = ctx . getKeyPairEDDSA ( ) ;
70- await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , { authMethod : AuthMethod . ECDSA } ) ;
92+ await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , {
93+ authMethod : AuthMethod . ECDSA
94+ } ) ;
7195
7296 // Submit
7397 await ctx . submitTransactions ( ) ;
7498 await ctx . submitPendingBlocks ( ) ;
7599
76100 // Try to update the account without approval
77- await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , { authMethod : AuthMethod . NONE } ) ;
101+ await ctx . requestAccountUpdate ( ownerB , token , fee , newKeyPair , {
102+ authMethod : AuthMethod . NONE
103+ } ) ;
78104
79105 // Submit
80106 await ctx . submitTransactions ( ) ;
81- await expectThrow (
82- ctx . submitPendingBlocks ( ) ,
83- "TX_NOT_APPROVED"
84- ) ;
107+ await expectThrow ( ctx . submitPendingBlocks ( ) , "TX_NOT_APPROVED" ) ;
108+ } ) ;
109+
110+ it ( "Should not be able to update an account with fee > maxFee" , async ( ) => {
111+ await createExchange ( ) ;
112+
113+ const balance = new BN ( web3 . utils . toWei ( "5484.24" , "ether" ) ) ;
114+ const token = ctx . getTokenAddress ( "LRC" ) ;
115+ const fee = ctx . getRandomFee ( ) ;
116+
117+ // Fund the payer
118+ await ctx . deposit ( ownerA , ownerA , token , balance ) ;
119+
120+ // Update the key pair of the new account
121+ let newKeyPair = ctx . getKeyPairEDDSA ( ) ;
122+ await ctx . requestAccountUpdate ( ownerA , token , fee , newKeyPair , {
123+ maxFee : fee . div ( new BN ( 2 ) )
124+ } ) ;
125+
126+ // Submit
127+ await expectThrow ( ctx . submitTransactions ( ) , "invalid block" ) ;
85128 } ) ;
86129 } ) ;
87130} ) ;
0 commit comments