diff --git a/dist/esm/index.bundle.js b/dist/esm/index.bundle.js index 73043992..10aa709e 100644 --- a/dist/esm/index.bundle.js +++ b/dist/esm/index.bundle.js @@ -22736,6 +22736,7 @@ var getTransactionByHash = (hash) => { let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -22747,7 +22748,7 @@ var getTransactionByHash = (hash) => { nonce: hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 9f197cd0..87501a9f 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -601,6 +601,7 @@ var getTransactionByHash = (hash) => { let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -612,7 +613,7 @@ var getTransactionByHash = (hash) => { nonce: ethers.utils.hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/dist/esm/index.js b/dist/esm/index.js index b042a950..0a8d2454 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -626,6 +626,7 @@ var getTransactionByHash = (hash) => { let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -637,7 +638,7 @@ var getTransactionByHash = (hash) => { nonce: ethers.utils.hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/dist/umd/index.bundle.js b/dist/umd/index.bundle.js index 590e2c76..3f1c78f2 100644 --- a/dist/umd/index.bundle.js +++ b/dist/umd/index.bundle.js @@ -22744,6 +22744,7 @@ let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -22755,7 +22756,7 @@ nonce: hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 40adf174..d36377b1 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -608,6 +608,7 @@ let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -619,7 +620,7 @@ nonce: ethers.ethers.utils.hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/dist/umd/index.js b/dist/umd/index.js index 5386c709..0e6854a7 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -632,6 +632,7 @@ let lastTransactionMock = mocks.find((mock)=>mock.transaction); let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d'; + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92'; let transaction = { from, @@ -643,7 +644,7 @@ nonce: ethers.ethers.utils.hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/package.evm.json b/package.evm.json index 326353ae..d7c20495 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-mock-evm", "moduleName": "Web3Mock", - "version": "14.4.1", + "version": "14.4.2", "description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.", "main": "./dist/umd/index.evm.js", "module": "./dist/esm/index.evm.js", diff --git a/package.json b/package.json index 690782e3..bb58e16f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-mock", "moduleName": "Web3Mock", - "version": "14.4.1", + "version": "14.4.2", "description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.", "main": "./dist/umd/index.js", "module": "./dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 2a96a400..e0a3a29e 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-mock-solana", "moduleName": "Web3Mock", - "version": "14.4.1", + "version": "14.4.2", "description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.", "main": "./dist/umd/index.solana.js", "module": "./dist/esm/index.solana.js", diff --git a/src/platforms/evm/transaction/getTransactionByHash.js b/src/platforms/evm/transaction/getTransactionByHash.js index 94d136b0..1488aa88 100644 --- a/src/platforms/evm/transaction/getTransactionByHash.js +++ b/src/platforms/evm/transaction/getTransactionByHash.js @@ -10,6 +10,7 @@ export default (hash) => { let lastTransactionMock = mocks.find((mock)=>mock.transaction) let from = (lastTransactionMock && lastTransactionMock.transaction.from) ? lastTransactionMock.transaction.from : '0xb7576e9d314df41ec5506494293afb1bd5d3f65d' + let to = (lastTransactionMock && lastTransactionMock.transaction.to) ? lastTransactionMock.transaction.to : '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92' let transaction = { from, @@ -21,7 +22,7 @@ export default (hash) => { nonce: ethers.utils.hexlify(getTransactionCount(from)), r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6', s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5', - to: null, + to, transactionIndex: '0x1', type: '0x0', v: '0x1c', diff --git a/tests/units/evm/transactions.evm.spec.js b/tests/units/evm/transactions.evm.spec.js index d2867ee2..a1cb20cb 100644 --- a/tests/units/evm/transactions.evm.spec.js +++ b/tests/units/evm/transactions.evm.spec.js @@ -76,6 +76,27 @@ describe('evm mock transactions (evm)', ()=> { expect(receipt.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390') }) + it('mocks a transaction', async ()=> { + + let mockedTransaction = mock({ + blockchain, + transaction: { + to: '0x5Af489c8786A018EC4814194dC8048be1007e390', + from: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", + value: "2000000000000000000" + } + }) + + expect(mockedTransaction.transaction._id).toBeDefined() + confirm(mockedTransaction) + + let provider = new ethers.providers.Web3Provider(global.ethereum); + + let transaction = await provider.getTransaction(mockedTransaction.transaction._id); + expect(transaction.from).toEqual('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') + expect(transaction.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390') + }) + it('mocks a complex contract transaction', async ()=> { let api = [{"inputs":[{"internalType":"address","name":"_configuration","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"configuration","outputs":[{"internalType":"contract DePayRouterV1Configuration","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pluginAddress","type":"address"}],"name":"isApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"address[]","name":"plugins","type":"address[]"},{"internalType":"string[]","name":"data","type":"string[]"}],"name":"route","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]; diff --git a/tests/units/evm/transactions.spec.js b/tests/units/evm/transactions.spec.js index a14bf792..0b52dd44 100644 --- a/tests/units/evm/transactions.spec.js +++ b/tests/units/evm/transactions.spec.js @@ -76,6 +76,27 @@ describe('evm mock transactions', ()=> { expect(receipt.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390') }) + it('mocks a transaction', async ()=> { + + let mockedTransaction = mock({ + blockchain, + transaction: { + to: '0x5Af489c8786A018EC4814194dC8048be1007e390', + from: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", + value: "2000000000000000000" + } + }) + + expect(mockedTransaction.transaction._id).toBeDefined() + confirm(mockedTransaction) + + let provider = new ethers.providers.Web3Provider(global.ethereum); + + let transaction = await provider.getTransaction(mockedTransaction.transaction._id); + expect(transaction.from).toEqual('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') + expect(transaction.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390') + }) + it('mocks a complex contract transaction', async ()=> { let api = [{"inputs":[{"internalType":"address","name":"_configuration","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"configuration","outputs":[{"internalType":"contract DePayRouterV1Configuration","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pluginAddress","type":"address"}],"name":"isApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"address[]","name":"plugins","type":"address[]"},{"internalType":"string[]","name":"data","type":"string[]"}],"name":"route","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}];