Skip to content

Commit

Permalink
Reapply update ethereumjs dependencies (#177) (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
brad-decker authored Mar 20, 2023
1 parent 9e1008e commit 571611d
Show file tree
Hide file tree
Showing 3 changed files with 439 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
},
"homepage": "/~https://github.com/MetaMask/eth-ledger-bridge-keyring#readme",
"dependencies": {
"@ethereumjs/tx": "^3.2.0",
"@ethereumjs/tx": "^4.1.1",
"eth-sig-util": "^2.0.0",
"ethereumjs-util": "^7.0.9",
"hdkey": "0.8.0"
},
"devDependencies": {
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/common": "^3.1.1",
"@lavamoat/allow-scripts": "^2.3.0",
"@metamask/eslint-config": "^3.0.0",
"babel-eslint": "^10.1.0",
Expand Down
26 changes: 19 additions & 7 deletions test/test-eth-ledger-bridge-keyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const EthereumTx = require('ethereumjs-tx')
const HDKey = require('hdkey')
const ethUtil = require('ethereumjs-util')
const { TransactionFactory } = require('@ethereumjs/tx')
const Common = require('@ethereumjs/common').default
const { Common, Chain, Hardfork } = require('@ethereumjs/common')
const sigUtil = require('eth-sig-util')

const LedgerBridgeKeyring = require('..')
Expand Down Expand Up @@ -47,8 +47,8 @@ const fakeTx = new EthereumTx({
chainId: 1,
})

const common = new Common({ chain: 'mainnet' })
const commonEIP1559 = Common.forCustomChain('mainnet', {}, 'london')
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin })
const commonEIP1559 = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const newFakeTx = TransactionFactory.fromTxData({
nonce: '0x00',
gasPrice: '0x09184e72a000',
Expand Down Expand Up @@ -522,8 +522,12 @@ describe('LedgerBridgeKeyring', function () {
}

await basicSetupToUnlockOneAccount()

sandbox.on(newFakeTx, 'verifySignature', () => true)
const signedNewFakeTx = TransactionFactory.fromTxData({
...newFakeTx.toJSON(),
...expectedRSV,
})
sandbox.on(TransactionFactory, 'fromTxData', () => signedNewFakeTx)
sandbox.on(signedNewFakeTx, 'verifySignature', () => true)
sandbox.on(keyring, '_sendMessage', (msg, cb) => {
assert.deepStrictEqual(msg.params, {
hdPath: "m/44'/60'/0'/0",
Expand All @@ -534,7 +538,7 @@ describe('LedgerBridgeKeyring', function () {

const returnedTx = await keyring.signTransaction(fakeAccounts[0], newFakeTx, common)
expect(keyring._sendMessage).to.have.been.called()
expect(returnedTx.toJSON()).to.deep.equal({ ...newFakeTx.toJSON(), ...expectedRSV })
expect(returnedTx.toJSON()).to.deep.equal(signedNewFakeTx.toJSON())
})

it('should pass correctly encoded EIP1559 transaction to ledger and return signed tx', async function () {
Expand All @@ -547,6 +551,14 @@ describe('LedgerBridgeKeyring', function () {

await basicSetupToUnlockOneAccount()

const signedFakeTypeTwoTx = TransactionFactory.fromTxData({
...fakeTypeTwoTx.toJSON(),
type: fakeTypeTwoTx.type,
...expectedRSV,
}, { common: commonEIP1559, freeze: false })
sandbox.on(TransactionFactory, 'fromTxData', () => signedFakeTypeTwoTx)
sandbox.on(signedFakeTypeTwoTx, 'verifySignature', () => true)

sandbox.on(fakeTypeTwoTx, 'verifySignature', () => true)
sandbox.on(keyring, '_sendMessage', (msg, cb) => {
assert.deepStrictEqual(msg.params, {
Expand All @@ -558,7 +570,7 @@ describe('LedgerBridgeKeyring', function () {

const returnedTx = await keyring.signTransaction(fakeAccounts[0], fakeTypeTwoTx, commonEIP1559)
expect(keyring._sendMessage).to.have.been.called()
expect(returnedTx.toJSON()).to.deep.equal({ ...fakeTypeTwoTx.toJSON(), ...expectedRSV })
expect(returnedTx.toJSON()).to.deep.equal(signedFakeTypeTwoTx.toJSON())
})
})
})
Expand Down
Loading

0 comments on commit 571611d

Please sign in to comment.