Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
devDeps(test): replace ethereumjs-util with @ethereumjs/util,ethereum…
Browse files Browse the repository at this point in the history
…-cryptography
  • Loading branch information
legobeat committed Oct 18, 2023
1 parent 4edf2ba commit 8470862
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"babelify": "^10.0.0",
"browserify": "^16.5.0",
"eslint": "^6.2.0",
"ethereum-cryptography": "^2.1.2",
"ethjs": "^0.3.6",
"ganache-core": "^2.7.0",
"tape": "^4.4.0"
Expand Down
4 changes: 2 additions & 2 deletions test/subproviders/etherscan.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sha3 = require('ethereumjs-util').sha3;
const { keccak_256 } = require('ethereum-cryptography');
const test = require('tape')
const ProviderEngine = require('../../index.js')
const createPayload = require('../../util/create-payload.js')
Expand Down Expand Up @@ -107,7 +107,7 @@ test('etherscan eth_getBalance', function(t) {
test('etherscan eth_call', function(t) {
t.plan(3)

var signature = Buffer.concat([sha3("getLatestBlock()", 256)], 4).toString('hex');
var signature = Buffer.concat([keccak_256(Buffer.from("getLatestBlock()"), 256)], 4).toString('hex');
var engine = new ProviderEngine()
var etherscan = new EtherscanSubprovider()
engine.addProvider(etherscan)
Expand Down
1 change: 0 additions & 1 deletion test/subproviders/ipc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const sha3 = require('ethereumjs-util').sha3;
const test = require('tape')
const ProviderEngine = require('../../index.js')
const createPayload = require('../../util/create-payload.js')
Expand Down
6 changes: 3 additions & 3 deletions test/subproviders/vm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('tape')
const async = require('async')
const ethUtil = require('ethereumjs-util')
const { toBuffer } = require('@ethereumjs/util')
const ProviderEngine = require('../../index.js')
const VmSubprovider = require('../../subproviders/vm')
const TestBlockProvider = require('../util/block.js')
Expand Down Expand Up @@ -39,14 +39,14 @@ test('binary search eth_estimateGas implementation', function(t) {
cb(new Error('fake out of gas'))
} else {
cb(null, {
gasUsed: ethUtil.toBuffer(scenario.gasNeeded),
gasUsed: toBuffer(scenario.gasNeeded),
});
}
}
engine.addProvider(vmSubprovider)
engine.addProvider(new TestBlockProvider());
engine.start()

engine.sendAsync(createPayload({
method: 'eth_estimateGas',
params: [{}, 'latest'],
Expand Down
18 changes: 9 additions & 9 deletions test/util/block.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const crypto = require('crypto')
const extend = require('xtend')
const ethUtil = require('ethereumjs-util')
const { addHexPrefix, bufferToHex, intToHex, stripHexPrefix } = require('@ethereumjs/util')
const FixtureProvider = require('../../subproviders/fixture.js')

//
Expand Down Expand Up @@ -108,7 +108,7 @@ function createBlock(blockParams, prevBlock, txs) {
blockParams = blockParams || {}
txs = txs || []
var defaultNumber = prevBlock ? incrementHex(prevBlock.number) : '0x1'
var defaultGasLimit = ethUtil.intToHex(4712388)
var defaultGasLimit = intToHex(4712388)
const result = extend({
// defaults
number: defaultNumber,
Expand All @@ -135,29 +135,29 @@ function createBlock(blockParams, prevBlock, txs) {
txs.forEach((tx, index) => {
tx.blockHash = result.hash
tx.blockNumber = result.number
tx.transactionIndex = ethUtil.intToHex(index)
tx.transactionIndex = intToHex(index)
})
return result
}

function incrementHex(hexString){
return stripLeadingZeroes(ethUtil.intToHex(Number(hexString)+1))
return stripLeadingZeroes(intToHex(Number(hexString)+1))
}

function randomHash(){
return ethUtil.bufferToHex(crypto.randomBytes(32))
return bufferToHex(crypto.randomBytes(32))
}

function randomAddress(){
return ethUtil.bufferToHex(crypto.randomBytes(20))
return bufferToHex(crypto.randomBytes(20))
}

function stripLeadingZeroes (hexString) {
let strippedHex = ethUtil.stripHexPrefix(hexString)
let strippedHex = stripHexPrefix(hexString)
while (strippedHex[0] === '0') {
strippedHex = strippedHex.substr(1)
}
return ethUtil.addHexPrefix(strippedHex)
return addHexPrefix(strippedHex)
}

module.exports = TestBlockProvider
module.exports = TestBlockProvider
2 changes: 1 addition & 1 deletion test/util/ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class GanacheProvider extends ProviderSubprovider {

}

module.exports = GanacheProvider
module.exports = GanacheProvider

0 comments on commit 8470862

Please sign in to comment.