Skip to content

Commit

Permalink
v14.5.0: mock transaction receipt logs
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed May 3, 2023
1 parent 6edf3d9 commit 7dacc2f
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dist/esm/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22781,9 +22781,9 @@ var getTransactionReceipt = (hash) => {
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$f([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$f([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$f([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,9 @@ var getTransactionReceipt = (hash) => {
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$b([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$b([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$b([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ var getTransactionReceipt = (hash) => {
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$f([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$f([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$f([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
Expand Down
4 changes: 2 additions & 2 deletions dist/umd/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22789,9 +22789,9 @@
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$f([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$f([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$f([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
Expand Down
4 changes: 2 additions & 2 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$b([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$b([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$b([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
Expand Down
4 changes: 2 additions & 2 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,9 @@
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: _optionalChain$f([mock, 'optionalAccess', _5 => _5.transaction, 'optionalAccess', _6 => _6.logs]) || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: _optionalChain$f([mock, 'access', _5 => _5.transaction, 'optionalAccess', _6 => _6._failed]) ? '0x0' : '0x1',
status: _optionalChain$f([mock, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8._failed]) ? '0x0' : '0x1',
})
} else {
return Promise.resolve(null)
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.2",
"version": "14.5.0",
"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.2",
"version": "14.5.0",
"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.2",
"version": "14.5.0",
"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
2 changes: 1 addition & 1 deletion src/platforms/evm/transaction/getTransactionReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default (hash) => {
blockHash: getRandomTransactionHash(mock.blockchain),
cumulativeGasUsed: '0x33bc',
gasUsed: '0x4dc',
logs: [],
logs: mock?.transaction?.logs || [],
logsBloom: '0x0000000000000000000000000000000000000000',
status: mock.transaction?._failed ? '0x0' : '0x1',
})
Expand Down
19 changes: 18 additions & 1 deletion tests/units/evm/transactions.evm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,29 @@ describe('evm mock transactions (evm)', ()=> {
})

it('mocks a transaction receipt', async ()=> {

let logs = [{
blockNumber: 16797899,
blockHash: '0x5948d965ab5805ace0bc7556672c8f475515ac853c4477f17cc49287f402430e',
transactionIndex: 65,
address: '0x6A12C2Cc8AF31f125484EB685F7c0bfcE280B919',
data: '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
topics: [
'0x83f5257fc3f5f94fa653d44d66c91bba315ce36d9c3c00b14278da4d3b635647',
'0x0000000000000000000000008f0a62ff2ae1fa08b25070b8b5138fb45630456f',
'0x000000000000000000000000fcd9c98aae3229a5984a27dee7e6c3b77f1622b5',
],
transactionHash: '0x1f6e88067388a82924535eaa2c4af83143652dba3ec518fbc1ee24d7522efa02',
logIndex: 226
}]

let mockedTransaction = mock({
blockchain,
transaction: {
to: '0x5Af489c8786A018EC4814194dC8048be1007e390',
from: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: "2000000000000000000"
value: "2000000000000000000",
logs
}
})

Expand All @@ -74,6 +90,7 @@ describe('evm mock transactions (evm)', ()=> {
let receipt = await provider.getTransactionReceipt(mockedTransaction.transaction._id);
expect(receipt.from).toEqual('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
expect(receipt.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390')
expect(receipt.logs).toEqual(logs)
})

it('mocks a transaction', async ()=> {
Expand Down
19 changes: 18 additions & 1 deletion tests/units/evm/transactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,29 @@ describe('evm mock transactions', ()=> {
})

it('mocks a transaction receipt', async ()=> {

let logs = [{
blockNumber: 16797899,
blockHash: '0x5948d965ab5805ace0bc7556672c8f475515ac853c4477f17cc49287f402430e',
transactionIndex: 65,
address: '0x6A12C2Cc8AF31f125484EB685F7c0bfcE280B919',
data: '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
topics: [
'0x83f5257fc3f5f94fa653d44d66c91bba315ce36d9c3c00b14278da4d3b635647',
'0x0000000000000000000000008f0a62ff2ae1fa08b25070b8b5138fb45630456f',
'0x000000000000000000000000fcd9c98aae3229a5984a27dee7e6c3b77f1622b5',
],
transactionHash: '0x1f6e88067388a82924535eaa2c4af83143652dba3ec518fbc1ee24d7522efa02',
logIndex: 226
}]

let mockedTransaction = mock({
blockchain,
transaction: {
to: '0x5Af489c8786A018EC4814194dC8048be1007e390',
from: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: "2000000000000000000"
value: "2000000000000000000",
logs
}
})

Expand All @@ -74,6 +90,7 @@ describe('evm mock transactions', ()=> {
let receipt = await provider.getTransactionReceipt(mockedTransaction.transaction._id);
expect(receipt.from).toEqual('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
expect(receipt.to).toEqual('0x5Af489c8786A018EC4814194dC8048be1007e390')
expect(receipt.logs).toEqual(logs)
})

it('mocks a transaction', async ()=> {
Expand Down

0 comments on commit 7dacc2f

Please sign in to comment.