Skip to content

Commit

Permalink
v14.4.2: mock transaction from + to
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed May 3, 2023
1 parent 5f346fa commit 6edf3d9
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dist/esm/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22747,7 +22748,7 @@ var getTransactionByHash = (hash) => {
nonce: hexlify(getTransactionCount(from)),
r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6',
s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5',
to: null,
to,
transactionIndex: '0x1',
type: '0x0',
v: '0x1c',
Expand Down
3 changes: 2 additions & 1 deletion dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion dist/umd/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22755,7 +22756,7 @@
nonce: hexlify(getTransactionCount(from)),
r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6',
s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5',
to: null,
to,
transactionIndex: '0x1',
type: '0x0',
v: '0x1c',
Expand Down
3 changes: 2 additions & 1 deletion dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -619,7 +620,7 @@
nonce: ethers.ethers.utils.hexlify(getTransactionCount(from)),
r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6',
s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5',
to: null,
to,
transactionIndex: '0x1',
type: '0x0',
v: '0x1c',
Expand Down
3 changes: 2 additions & 1 deletion dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -643,7 +644,7 @@
nonce: ethers.ethers.utils.hexlify(getTransactionCount(from)),
r: '0xcfb56087c168a48bc69bd2634172fd9defd77bd172387e2137643906ff3606f6',
s: '0x3474eb47999927f2bed4d4ec27d7e8bb4ad17c61d76761e40fdbd859d84c3bd5',
to: null,
to,
transactionIndex: '0x1',
type: '0x0',
v: '0x1c',
Expand Down
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/evm/transaction/getTransactionByHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions tests/units/evm/transactions.evm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"}];
Expand Down
21 changes: 21 additions & 0 deletions tests/units/evm/transactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"}];
Expand Down

0 comments on commit 6edf3d9

Please sign in to comment.