@@ -2,17 +2,13 @@ const fs = require('fs')
22const path = require ( 'path' )
33const test = require ( 'tape' )
44const ganache = require ( 'ganache' )
5- const provider = ganache . provider ( )
6-
5+ const { Web3Provider } = require ( '@ethersproject/providers' )
6+ const { ContractFactory } = require ( '@ethersproject/contracts' )
77const solc = require ( 'solc' )
88const TokenTracker = require ( '../../lib' )
9- const BN = ( 'bn.js' )
109
11- const Eth = require ( '@metamask/ethjs-query' )
12- const EthContract = require ( '@metamask/ethjs-contract' )
13- const eth = new Eth ( provider )
14- const contract = new EthContract ( eth )
1510
11+ const provider = ganache . provider ( )
1612const source = fs . readFileSync ( path . resolve ( __dirname , '..' , 'contracts/Token.sol' ) ) . toString ( ) ;
1713const compiled = solc . compile ( source , 1 )
1814const HumanStandardDeployer = compiled . contracts [ ':HumanStandardToken' ]
@@ -23,8 +19,10 @@ const EXPECTED_SYMBOL = 'EXP'
2319let addresses = [ ]
2420let token , tokenAddress , tracked
2521
22+ const ethersProvider = new Web3Provider ( provider )
23+
2624test ( 'testrpc has addresses' , function ( t ) {
27- eth . accounts ( )
25+ ethersProvider . listAccounts ( )
2826 . then ( ( accounts ) => {
2927 addresses = accounts
3028 t . ok ( accounts , 'loaded accounts' )
@@ -34,34 +32,23 @@ test('testrpc has addresses', function (t) {
3432
3533test ( 'HumanStandardToken publishing token & checking balance' , function ( t ) {
3634 const abi = JSON . parse ( HumanStandardDeployer . interface )
37- const HumanStandardToken = contract ( abi , HumanStandardDeployer . bytecode , {
38- from : addresses [ 0 ] ,
39- gas : '3000000' ,
40- gasPrice : '875000000' ,
41- } )
42- const humanStandardToken = HumanStandardToken . new ( '1000' ,
43- 'DanBucks' ,
44- '2' , // decimals
45- SET_SYMBOL )
46- . then ( ( txHash ) => {
47- t . ok ( txHash , 'publishes a txHash' )
35+ const factory = new ContractFactory ( abi , HumanStandardDeployer . bytecode , ethersProvider . getSigner ( addresses [ 0 ] ) )
4836
49- return new Promise ( ( res , rej ) => {
50- setTimeout ( ( ) => res ( txHash ) , 200 )
51- } )
37+ factory . deploy ( '1000' , 'DanBucks' , '2' , SET_SYMBOL , {
38+ gasLimit : '3000000' ,
39+ gasPrice : '875000000' ,
5240 } )
53- . then ( ( txHash ) => {
54- return eth . getTransactionReceipt ( txHash )
41+ . then ( ( contract ) => {
42+ t . ok ( contract . deployTransaction . hash , 'publishes a txHash' )
43+ return contract . deployed ( )
5544 } )
56- . then ( ( receipt ) => {
57- const addr = receipt . contractAddress
58- tokenAddress = addr
59- token = HumanStandardToken . at ( addr )
45+ . then ( ( deployedContract ) => {
46+ token = deployedContract
47+ tokenAddress = token . address
6048 return token . balanceOf ( addresses [ 0 ] )
6149 } )
62- . then ( ( res ) => {
63- const balance = res [ 0 ]
64- t . equal ( balance . toString ( 10 ) , '1000' , 'owner should have all' )
50+ . then ( ( balance ) => {
51+ t . equal ( balance . toString ( ) , '1000' , 'owner should have all' )
6552 t . end ( )
6653 } )
6754 . catch ( ( reason ) => {
@@ -90,8 +77,8 @@ test('HumanStandardToken balances are tracked', function (t) {
9077 t . equal ( tracked . balance . toString ( 10 ) , '1000' , 'initial balance loaded' )
9178 return token . transfer ( addresses [ 1 ] , '110' )
9279 } )
93- . then ( ( txHash ) => {
94- return eth . getTransactionReceipt ( txHash )
80+ . then ( ( tx ) => {
81+ return ethersProvider . getTransactionReceipt ( tx . hash )
9582 } )
9683 . then ( ( receipt ) => {
9784 var a = new Promise ( ( res , rej ) => { setTimeout ( res , 200 ) } )
0 commit comments