@@ -26,8 +26,8 @@ declare module '../web3_export_helper' {
2626 }
2727}
2828
29- describe ( 'CustomRpcMethodsPlugin Tests ' , ( ) => {
30- it ( 'should register CustomRpcMethodsPlugin plugin' , ( ) => {
29+ describe ( 'ContractMethodWrappersPlugin ' , ( ) => {
30+ it ( 'should register the plugin' , ( ) => {
3131 const web3 = new Web3 ( 'http://127.0.0.1:8545' ) ;
3232 web3 . registerPlugin (
3333 new ContractMethodWrappersPlugin (
@@ -38,7 +38,7 @@ describe('CustomRpcMethodsPlugin Tests', () => {
3838 expect ( web3 . contractMethodWrappersPlugin ) . toBeDefined ( ) ;
3939 } ) ;
4040
41- describe ( 'CustomRpcMethodsPlugin methods tests ' , ( ) => {
41+ describe ( 'methods' , ( ) => {
4242 const contractAddress = '0xdAC17F958D2ee523a2206206994597C13D831ec7' ;
4343 const sender = '0x8da5e39ec14b57fb9bcd9aa2b4500e909119795d' ;
4444 const recipient = '0x4f641def1e7845caab95ac717c80416082430d0d' ;
@@ -47,17 +47,21 @@ describe('CustomRpcMethodsPlugin Tests', () => {
4747 '0x0000000000000000000000000000000000000000000000000000000000000280' ;
4848 const expectedRecipientBalance =
4949 '0x0000000000000000000000000000000000000000000000000000000000000120' ;
50- const requestManagerSendSpy = jest . fn ( ) ;
50+ let requestManagerSendSpy : jest . Mock ;
5151
5252 let web3 : Web3 ;
5353
5454 beforeAll ( ( ) => {
5555 web3 = new Web3 ( 'http://127.0.0.1:8545' ) ;
5656 web3 . registerPlugin ( new ContractMethodWrappersPlugin ( ERC20TokenAbi , contractAddress ) ) ;
57+ } ) ;
58+
59+ beforeEach ( ( ) => {
60+ requestManagerSendSpy = jest . fn ( ) ;
5761 web3 . contractMethodWrappersPlugin . _contract . requestManager . send = requestManagerSendSpy ;
5862 } ) ;
5963
60- it ( 'should call contractMethodWrappersPlugin. getFormattedBalance with expected RPC object' , async ( ) => {
64+ it ( 'should call ` getFormattedBalance` with expected RPC object' , async ( ) => {
6165 requestManagerSendSpy . mockResolvedValueOnce ( expectedSenderBalance ) ;
6266
6367 await web3 . contractMethodWrappersPlugin . getFormattedBalance (
@@ -67,17 +71,16 @@ describe('CustomRpcMethodsPlugin Tests', () => {
6771 expect ( requestManagerSendSpy ) . toHaveBeenCalledWith ( {
6872 method : 'eth_call' ,
6973 params : [
70- {
74+ expect . objectContaining ( {
7175 input : '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d' ,
72- data : '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d' ,
7376 to : '0xdAC17F958D2ee523a2206206994597C13D831ec7' ,
74- } ,
77+ } ) ,
7578 'latest' ,
7679 ] ,
7780 } ) ;
7881 } ) ;
7982
80- it ( 'should call CustomRpcMethodsPlugin.customRpcMethodWithParameters with expected RPC object' , async ( ) => {
83+ it ( 'should call `transferAndGetBalances` with expected RPC object' , async ( ) => {
8184 const expectedGasPrice = '0x1ca14bd70' ;
8285 const expectedTransactionHash =
8386 '0xc41b9a4f654c44552e135f770945916f57c069b80326f9a5f843e613491ab6b1' ;
@@ -98,20 +101,22 @@ describe('CustomRpcMethodsPlugin Tests', () => {
98101 recipient ,
99102 amount ,
100103 ) ;
101- expect ( requestManagerSendSpy ) . toHaveBeenCalledWith ( {
104+
105+ // The first call will be to `eth_gasPrice` and the second is to `eth_blockNumber`. And the third one will be to `eth_sendTransaction`:
106+ expect ( requestManagerSendSpy ) . toHaveBeenNthCalledWith ( 3 , {
102107 method : 'eth_sendTransaction' ,
103108 params : [
104- {
109+ expect . objectContaining ( {
105110 input : '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a' ,
106- data : '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a' ,
107111 from : sender ,
108112 gasPrice : expectedGasPrice ,
109113 maxFeePerGas : undefined ,
110114 maxPriorityFeePerGas : undefined ,
111115 to : contractAddress ,
112- } ,
116+ } ) ,
113117 ] ,
114118 } ) ;
119+
115120 expect ( balances ) . toStrictEqual ( {
116121 sender : {
117122 address : sender ,
0 commit comments