1
1
import winston from "winston" ;
2
- import { assert , web3 } from "hardhat " ;
2
+ import { assert } from "chai " ;
3
3
import { Contract } from "web3-eth-contract" ;
4
- import { getTruffleContract } from "@uma/core" ;
5
4
import sinon from "sinon" ;
6
5
import { Relayer } from "../src/Relayer" ;
6
+ import { getAbi } from "@uma/contracts-node" ;
7
7
import { SpyTransport , GasEstimator , lastSpyLogIncludes } from "@uma/financial-templates-lib" ;
8
8
import { ZERO_ADDRESS , interfaceName , RegistryRolesEnum } from "@uma/common" ;
9
9
10
+ const { getContract, deployments, web3 } = require ( "hardhat" ) ;
11
+
10
12
const { utf8ToHex, hexToUtf8 } = web3 . utils ;
11
- const Finder = getTruffleContract ( "Finder" , web3 ) ;
12
- const OracleChildTunnel = getTruffleContract ( "OracleChildTunnel" , web3 ) ;
13
- const Registry = getTruffleContract ( "Registry" , web3 ) ;
14
- const OracleRootTunnel = getTruffleContract ( "OracleRootTunnelMock" , web3 ) ;
15
- const MockOracle = getTruffleContract ( "MockOracleAncillary" , web3 ) ;
16
- const StateSync = getTruffleContract ( "StateSyncMock" , web3 ) ;
17
- const FxChild = getTruffleContract ( "FxChildMock" , web3 ) ;
18
- const FxRoot = getTruffleContract ( "FxRootMock" , web3 ) ;
13
+ const Finder = getContract ( "Finder" ) ;
14
+ const OracleChildTunnel = getContract ( "OracleChildTunnel" ) ;
15
+ const Registry = getContract ( "Registry" ) ;
16
+ const OracleRootTunnel = getContract ( "OracleRootTunnelMock" ) ;
17
+ const MockOracle = getContract ( "MockOracleAncillary" ) ;
18
+ const StateSync = getContract ( "StateSyncMock" ) ;
19
+ const FxChild = getContract ( "FxChildMock" ) ;
20
+ const FxRoot = getContract ( "FxRootMock" ) ;
19
21
20
22
// This function should return a bytes string.
21
23
type customPayloadFn = ( ) => Promise < string > ;
@@ -57,33 +59,34 @@ describe("Relayer unit tests", function () {
57
59
// Note: We deploy all contracts on local hardhat network to make testing more convenient.
58
60
59
61
// Set up mocked Fx tunnel:
60
- stateSync = await StateSync . new ( ) ;
61
- fxRoot = await FxRoot . new ( stateSync . address ) ;
62
- fxChild = await FxChild . new ( systemSuperUser ) ;
63
- await fxChild . setFxRoot ( fxRoot . address , { from : owner } ) ;
64
- await fxRoot . setFxChild ( fxChild . address , { from : owner } ) ;
62
+ stateSync = await StateSync . new ( ) . send ( { from : owner } ) ;
63
+ fxRoot = await FxRoot . new ( stateSync . options . address ) . send ( { from : owner } ) ;
64
+ fxChild = await FxChild . new ( systemSuperUser ) . send ( { from : owner } ) ;
65
+ await fxChild . methods . setFxRoot ( fxRoot . options . address ) . send ( { from : owner } ) ;
66
+ await fxRoot . methods . setFxChild ( fxChild . options . address ) . send ( { from : owner } ) ;
65
67
66
68
// Set up mocked Oracle infrastructure
67
- finder = await Finder . new ( ) ;
68
- mockOracle = await MockOracle . new ( finder . address , ZERO_ADDRESS ) ;
69
- await finder . changeImplementationAddress ( utf8ToHex ( interfaceName . Oracle ) , mockOracle . address ) ;
70
- registry = await Registry . new ( ) ;
71
- await finder . changeImplementationAddress ( utf8ToHex ( interfaceName . Registry ) , registry . address ) ;
72
- await registry . addMember ( RegistryRolesEnum . CONTRACT_CREATOR , owner , { from : owner } ) ;
73
- await registry . registerContract ( [ ] , owner , { from : owner } ) ;
69
+ finder = await Finder . new ( ) . send ( { from : owner } ) ;
70
+ mockOracle = await MockOracle . new ( finder . options . address , ZERO_ADDRESS ) . send ( { from : owner } ) ;
71
+ await finder . methods
72
+ . changeImplementationAddress ( utf8ToHex ( interfaceName . Oracle ) , mockOracle . options . address )
73
+ . send ( { from : owner } ) ;
74
+ registry = await Registry . new ( ) . send ( { from : owner } ) ;
75
+ await finder . methods
76
+ . changeImplementationAddress ( utf8ToHex ( interfaceName . Registry ) , registry . options . address )
77
+ . send ( { from : owner } ) ;
78
+ await registry . methods . addMember ( RegistryRolesEnum . CONTRACT_CREATOR , owner ) . send ( { from : owner } ) ;
79
+ await registry . methods . registerContract ( [ ] , owner ) . send ( { from : owner } ) ;
74
80
} ) ;
75
81
76
82
beforeEach ( async function ( ) {
77
83
// Deploy new tunnel contracts so that event logs are fresh for each test
78
- const _oracleChild = await OracleChildTunnel . new ( fxChild . address , finder . address ) ;
79
- const _oracleRoot = await OracleRootTunnel . new ( checkpointManager , fxRoot . address , finder . address ) ;
80
- await _oracleChild . setFxRootTunnel ( _oracleRoot . address , { from : owner } ) ;
81
- await _oracleRoot . setFxChildTunnel ( _oracleChild . address , { from : owner } ) ;
82
-
83
- // Create Web3.eth.Contract versions of Tunnel contracts so that we can interact with them the same way
84
- // that the relayer bot does.
85
- oracleChild = new web3 . eth . Contract ( OracleChildTunnel . abi , _oracleChild . address ) ;
86
- oracleRoot = new web3 . eth . Contract ( OracleRootTunnel . abi , _oracleRoot . address ) ;
84
+ oracleChild = await OracleChildTunnel . new ( fxChild . options . address , finder . options . address ) . send ( { from : owner } ) ;
85
+ oracleRoot = await OracleRootTunnel . new ( checkpointManager , fxRoot . options . address , finder . options . address ) . send ( {
86
+ from : owner ,
87
+ } ) ;
88
+ await oracleChild . methods . setFxRootTunnel ( oracleRoot . options . address ) . send ( { from : owner } ) ;
89
+ await oracleRoot . methods . setFxChildTunnel ( oracleChild . options . address ) . send ( { from : owner } ) ;
87
90
88
91
// The OracleChildTunnel should stamp ",childRequester:<requester-address>,childChainId:<chain-id>" to the original
89
92
// ancillary data.
@@ -107,6 +110,11 @@ describe("Relayer unit tests", function () {
107
110
} ) ,
108
111
} ,
109
112
} ;
113
+
114
+ // Save to hre.deployments so that client can fetch contract addresses via getAddress.
115
+ deployments . save ( "OracleChildTunnel" , { address : oracleChild . options . address , abi : getAbi ( "OracleChildTunnel" ) } ) ;
116
+ deployments . save ( "OracleRootTunnel" , { address : oracleChild . options . address , abi : getAbi ( "OracleRootTunnel" ) } ) ;
117
+
110
118
// Construct Relayer that should relay messages without fail.
111
119
relayer = new Relayer ( spyLogger , owner , gasEstimator , maticPosClient , oracleChild , oracleRoot , web3 , 0 ) ;
112
120
} ) ;
0 commit comments