2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
import { LegacyTransaction } from '@ethereumjs/tx'
5
- import { Account , Address } from '@ethereumjs/util'
5
+ import { Account , Address , hexToBytes } from '@ethereumjs/util'
6
6
import { generateKey } from '@ironfish/rust-nodejs'
7
7
import { Assert , ContractArtifact , IronfishEvm } from '@ironfish/sdk'
8
8
import { ethers } from 'ethers'
@@ -32,19 +32,16 @@ export class TestEvmCommand extends IronfishCommand {
32
32
await node . chain . blockchainDb . stateManager . putAccount ( senderAddress , senderAccount )
33
33
await node . chain . blockchainDb . stateManager . commit ( )
34
34
35
- // Deploy the global contract
36
- const tx = new LegacyTransaction ( {
37
- gasLimit : 1_000_000n ,
38
- data : ContractArtifact . bytecode ,
39
- } )
40
-
41
- const result = await evm . runTx ( { tx : tx . sign ( senderPrivateKey ) } )
42
-
43
- const globalContractAddress = result . createdAddress
35
+ const globalContractAddress = Address . fromString (
36
+ '0xffffffffffffffffffffffffffffffffffffffff' ,
37
+ )
44
38
45
- if ( ! globalContractAddress ) {
46
- this . error ( 'Contract creation of address failed' )
47
- }
39
+ await node . chain . blockchainDb . stateManager . checkpoint ( )
40
+ await node . chain . blockchainDb . stateManager . putContractCode (
41
+ globalContractAddress ,
42
+ hexToBytes ( ContractArtifact . deployedBytecode ) ,
43
+ )
44
+ await node . chain . blockchainDb . stateManager . commit ( )
48
45
49
46
const contract = await node . chain . blockchainDb . stateManager . getAccount (
50
47
globalContractAddress ,
@@ -58,24 +55,24 @@ export class TestEvmCommand extends IronfishCommand {
58
55
59
56
const globalContract = new ethers . Interface ( ContractArtifact . abi )
60
57
61
- const data2 = globalContract . encodeFunctionData ( 'shield' , [
58
+ const data = globalContract . encodeFunctionData ( 'shield' , [
62
59
Buffer . from ( senderKey . publicAddress , 'hex' ) ,
63
60
2n ,
64
61
100n ,
65
62
] )
66
63
67
- const tx2 = new LegacyTransaction ( {
68
- nonce : 1n ,
64
+ const tx = new LegacyTransaction ( {
65
+ nonce : 0n ,
69
66
gasLimit : 100_000n ,
70
67
to : globalContractAddress ,
71
- data : data2 ,
68
+ data : data ,
72
69
} )
73
70
74
- const result2 = await evm . runTx ( { tx : tx2 . sign ( senderPrivateKey ) } )
71
+ const result = await evm . runTx ( { tx : tx . sign ( senderPrivateKey ) } )
75
72
76
- Assert . isEqual ( result2 . receipt . logs . length , 1 )
73
+ Assert . isEqual ( result . receipt . logs . length , 1 )
77
74
78
- const log = result2 . receipt . logs [ 0 ]
75
+ const log = result . receipt . logs [ 0 ]
79
76
80
77
this . log ( 'Contract Address' )
81
78
this . log ( Buffer . from ( log [ 0 ] ) . toString ( 'hex' ) )
0 commit comments