-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* eth_call test * eth_chainId test * run json rpc tests * add ci job * remove query string param from url * eth_sendTransaction test * eth_sendTransaction test --------- Co-authored-by: Brad Decker <[email protected]>
- Loading branch information
1 parent
7e824fd
commit 378bf19
Showing
6 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { strict: assert } = require('assert'); | ||
const { keccak256 } = require('@truffle/codec/dist/lib/evm/utils'); | ||
const { convertToHexValue, withFixtures } = require('../helpers'); | ||
const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); | ||
const FixtureBuilder = require('../fixture-builder'); | ||
|
||
describe('eth_call', function () { | ||
const smartContract = SMART_CONTRACTS.NFTS; | ||
const ganacheOptions = { | ||
accounts: [ | ||
{ | ||
secretKey: | ||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', | ||
balance: convertToHexValue(25000000000000000000), | ||
}, | ||
], | ||
}; | ||
it('executes a new message call', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.build(), | ||
ganacheOptions, | ||
smartContract, | ||
title: this.test.title, | ||
}, | ||
async ({ driver, _, contractRegistry }) => { | ||
const contract = contractRegistry.getContractAddress(smartContract); | ||
await driver.navigate(); | ||
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); | ||
|
||
// eth_call | ||
await driver.openNewPage(`http://127.0.0.1:8080`); | ||
const balanceOf = `0x${keccak256('balanceOf(address)').toString( | ||
'hex', | ||
)}`; | ||
const walletAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; | ||
const request = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_call', | ||
params: [ | ||
{ | ||
to: `${contract}`, | ||
data: | ||
`${balanceOf.slice(0, 10)}` + | ||
'000000000000000000000000' + | ||
`${walletAddress.substring(2)}`, | ||
}, | ||
'latest', | ||
], | ||
id: 0, | ||
}); | ||
const result = await driver.executeScript( | ||
`return window.ethereum.request(${request})`, | ||
); | ||
|
||
assert.equal( | ||
result, | ||
'0x0000000000000000000000000000000000000000000000000000000000000001', | ||
); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { strict: assert } = require('assert'); | ||
const { convertToHexValue, withFixtures } = require('../helpers'); | ||
const FixtureBuilder = require('../fixture-builder'); | ||
|
||
describe('eth_chainId', function () { | ||
const ganacheOptions = { | ||
accounts: [ | ||
{ | ||
secretKey: | ||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', | ||
balance: convertToHexValue(25000000000000000000), | ||
}, | ||
], | ||
}; | ||
it('returns the chain ID of the current network', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.build(), | ||
ganacheOptions, | ||
title: this.test.title, | ||
}, | ||
async ({ driver }) => { | ||
await driver.navigate(); | ||
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); | ||
|
||
// eth_chainId | ||
await driver.openNewPage(`http://127.0.0.1:8080`); | ||
const request = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_chainId', | ||
params: [], | ||
id: 0, | ||
}); | ||
const result = await driver.executeScript( | ||
`return window.ethereum.request(${request})`, | ||
); | ||
|
||
assert.equal(result, '0x539'); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
const { strict: assert } = require('assert'); | ||
const { convertToHexValue, withFixtures } = require('../helpers'); | ||
const FixtureBuilder = require('../fixture-builder'); | ||
|
||
describe('eth_sendTransaction', function () { | ||
const ganacheOptions = { | ||
hardfork: 'london', | ||
accounts: [ | ||
{ | ||
secretKey: | ||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', | ||
balance: convertToHexValue(25000000000000000000), | ||
}, | ||
], | ||
}; | ||
const expectedHash = | ||
'0x855951a65dcf5949dc54beb032adfb604c52a0a548a0f616799d6873a9521470'; | ||
it('confirms a new transaction', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.build(), | ||
ganacheOptions, | ||
title: this.test.title, | ||
}, | ||
async ({ driver }) => { | ||
await driver.navigate(); | ||
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); | ||
|
||
// eth_sendTransaction | ||
await driver.openNewPage(`http://127.0.0.1:8080`); | ||
const request = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_sendTransaction', | ||
params: [ | ||
{ | ||
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', | ||
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', | ||
value: '0x0', | ||
maxPriorityFeePerGas: '0x3b9aca00', | ||
maxFeePerGas: '0x2540be400', | ||
}, | ||
], | ||
id: 0, | ||
}); | ||
await driver.executeScript( | ||
`window.transactionHash = window.ethereum.request(${request})`, | ||
); | ||
|
||
// confirm transaction in mm popup | ||
await driver.waitUntilXWindowHandles(3); | ||
await driver.switchToWindowWithTitle('MetaMask Notification'); | ||
await driver.clickElement({ text: 'Confirm', tag: 'button' }); | ||
await driver.switchToWindowWithTitle('E2E Test Dapp'); | ||
const actualHash = await driver.executeScript( | ||
`return window.transactionHash;`, | ||
); | ||
assert.equal(actualHash, expectedHash); | ||
}, | ||
); | ||
}); | ||
it('rejects a new transaction', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.build(), | ||
ganacheOptions, | ||
title: this.test.title, | ||
}, | ||
async ({ driver }) => { | ||
await driver.navigate(); | ||
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); | ||
|
||
// eth_sendTransaction | ||
await driver.openNewPage(`http://127.0.0.1:8080`); | ||
const request = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_sendTransaction', | ||
params: [ | ||
{ | ||
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', | ||
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', | ||
value: '0x0', | ||
maxPriorityFeePerGas: '0x3b9aca00', | ||
maxFeePerGas: '0x2540be400', | ||
}, | ||
], | ||
id: 0, | ||
}); | ||
await driver.executeScript( | ||
`window.transactionHash = window.ethereum.request(${request})`, | ||
); | ||
|
||
// reject transaction in mm popup | ||
await driver.waitUntilXWindowHandles(3); | ||
await driver.switchToWindowWithTitle('MetaMask Notification'); | ||
await driver.clickElement({ text: 'Reject', tag: 'button' }); | ||
await driver.switchToWindowWithTitle('E2E Test Dapp'); | ||
const result = await driver | ||
.executeScript(`return window.transactionHash;`) | ||
.then((data) => { | ||
return data; | ||
}) | ||
.catch((err) => { | ||
return err; | ||
}); | ||
assert.ok( | ||
result.message.includes( | ||
'MetaMask Tx Signature: User denied transaction signature.', | ||
), | ||
); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters