Skip to content

Commit

Permalink
fix: Equalizing dependencies' versions (#782)
Browse files Browse the repository at this point in the history
* Normalizing dependency versions

* lint: Side-effects of package updates

* Updates merkle-patricia-tree dep

* test: side-effect of updating nyc

* Updates @types/tape dep

* refactor: using tape whithout paths

* Updates -tx and ethereumjs-util
  • Loading branch information
evertonfraga authored and jochem-brouwer committed Jun 23, 2020
1 parent 6b06b6d commit b571b8e
Show file tree
Hide file tree
Showing 31 changed files with 333 additions and 333 deletions.
24 changes: 12 additions & 12 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
"homepage": "https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/account#synopsis",
"dependencies": {
"ethereumjs-util": "^7.0.2",
"rlp": "^2.2.1",
"rlp": "^2.2.3",
"safe-buffer": "^5.1.1"
},
"devDependencies": {
"@ethereumjs/config-nyc": "^1.1.0",
"@ethereumjs/config-prettier": "^1.1.0",
"@ethereumjs/config-tsc": "^1.1.0",
"@ethereumjs/config-tslint": "^1.1.0",
"@ethereumjs/config-nyc": "^1.1.1",
"@ethereumjs/config-prettier": "^1.1.1",
"@ethereumjs/config-tsc": "^1.1.1",
"@ethereumjs/config-tslint": "^1.1.1",
"@types/bn.js": "^4.11.6",
"@types/node": "^11.9.4",
"@types/tape": "^4.2.33",
"@types/node": "^11.13.4",
"@types/tape": "^4.13.0",
"merkle-patricia-tree": "^3.0.0",
"nyc": "^13.2.0",
"prettier": "^1.15.3",
"nyc": "^14.0.0",
"prettier": "^2.0.5",
"tape": "^4.10.1",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
"ts-node": "^8.8.2",
"tslint": "^5.16.0",
"typedoc": "next",
"typedoc-plugin-markdown": "^2.2.17",
"typescript": "^3.9.2",
"typescript": "^3.9.3",
"typestrict": "^1.0.2"
}
}
54 changes: 27 additions & 27 deletions packages/account/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as rlp from 'rlp'
import Account from '../src/index'
const SecureTrie = require('merkle-patricia-tree/secure')

tape('empty constructor', function(tester) {
tape('empty constructor', function (tester) {
const it = tester.test
it('should work', function(t) {
it('should work', function (t) {
const account = new Account()
t.equal(account.nonce.toString('hex'), '')
t.equal(account.balance.toString('hex'), '')
Expand All @@ -21,9 +21,9 @@ tape('empty constructor', function(tester) {
})
})

tape('constructor with Array', function(tester) {
tape('constructor with Array', function (tester) {
const it = tester.test
it('should work', function(t) {
it('should work', function (t) {
const raw = [
'0x02', // nonce
'0x0384', // balance
Expand All @@ -45,9 +45,9 @@ tape('constructor with Array', function(tester) {
})
})

tape('constructor with Object', function(tester) {
tape('constructor with Object', function (tester) {
const it = tester.test
it('should work', function(t) {
it('should work', function (t) {
const raw = {
nonce: '0x02',
balance: '0x0384',
Expand All @@ -69,9 +69,9 @@ tape('constructor with Object', function(tester) {
})
})

tape('constructor with RLP', function(tester) {
tape('constructor with RLP', function (tester) {
const it = tester.test
it('should work', function(t) {
it('should work', function (t) {
const account = new Account(
'f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
)
Expand All @@ -89,9 +89,9 @@ tape('constructor with RLP', function(tester) {
})
})

tape('serialize', function(tester) {
tape('serialize', function (tester) {
const it = tester.test
it('should work', function(t) {
it('should work', function (t) {
const raw = {
nonce: '0x01',
balance: '0x0042',
Expand All @@ -110,16 +110,16 @@ tape('serialize', function(tester) {
})
})

tape('isContract', function(tester) {
tape('isContract', function (tester) {
const it = tester.test
it('should return false', function(t) {
it('should return false', function (t) {
const account = new Account(
'f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
)
t.equal(account.isContract(), false)
t.end()
})
it('should return true', function(t) {
it('should return true', function (t) {
const raw = {
nonce: '0x01',
balance: '0x0042',
Expand All @@ -132,9 +132,9 @@ tape('isContract', function(tester) {
})
})

tape('setCode && getCode', tester => {
tape('setCode && getCode', (tester) => {
const it = tester.test
it('should set and get code', t => {
it('should set and get code', (t) => {
const code = Buffer.from(
'73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157',
'hex',
Expand All @@ -149,43 +149,43 @@ tape('setCode && getCode', tester => {
const account = new Account(raw)
const trie = new SecureTrie()

account.setCode(trie, code, function(err, codeHash) {
account.getCode(trie, function(err, codeRetrieved) {
account.setCode(trie, code, function (err, codeHash) {
account.getCode(trie, function (err, codeRetrieved) {
t.equals(Buffer.compare(code, codeRetrieved!), 0)
t.end()
})
})
})
it('should not get code if is not contract', t => {
it('should not get code if is not contract', (t) => {
const raw = {
nonce: '0x0',
balance: '0x03e7',
}
const account = new Account(raw)
const trie = new SecureTrie()
account.getCode(trie, function(err, code) {
account.getCode(trie, function (err, code) {
t.equals(Buffer.compare(code!, Buffer.alloc(0)), 0)
t.end()
})
})
it('should set empty code', t => {
it('should set empty code', (t) => {
const raw = {
nonce: '0x0',
balance: '0x03e7',
}
const account = new Account(raw)
const trie = new SecureTrie()
const code = Buffer.alloc(0)
account.setCode(trie, code, function(err, codeHash) {
account.setCode(trie, code, function (err, codeHash) {
t.equals(Buffer.compare(codeHash, Buffer.alloc(0)), 0)
t.end()
})
})
})

tape('setStorage && getStorage', tester => {
tape('setStorage && getStorage', (tester) => {
const it = tester.test
it('should set and get storage', t => {
it('should set and get storage', (t) => {
const raw = {
nonce: '0x0',
balance: '0x03e7',
Expand All @@ -197,7 +197,7 @@ tape('setStorage && getStorage', tester => {
const key = Buffer.from('0000000000000000000000000000000000000000', 'hex')
const value = Buffer.from('01', 'hex')

account.setStorage(trie, key, value, err => {
account.setStorage(trie, key, value, (err) => {
account.getStorage(trie, key, (err, valueRetrieved) => {
t.equals(Buffer.compare(value, valueRetrieved!), 0)
t.end()
Expand All @@ -206,14 +206,14 @@ tape('setStorage && getStorage', tester => {
})
})

tape('isEmpty', tester => {
tape('isEmpty', (tester) => {
const it = tester.test
it('should return true for an empty account', t => {
it('should return true for an empty account', (t) => {
const account = new Account()
t.ok(account.isEmpty())
t.end()
})
it('should return false for a non-empty account', t => {
it('should return false for a non-empty account', (t) => {
const raw = {
nonce: '0x01',
balance: '0x0042',
Expand Down
20 changes: 10 additions & 10 deletions packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"homepage": "https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/block#synopsis",
"dependencies": {
"@ethereumjs/common": "^1.5.0",
"@ethereumjs/tx": "^2.1.1",
"@ethereumjs/tx": "^2.1.2",
"@types/bn.js": "^4.11.6",
"ethereumjs-util": "^7.0.2",
"merkle-patricia-tree": "^2.1.2"
"merkle-patricia-tree": "^2.3.2"
},
"devDependencies": {
"@ethereumjs/config-nyc": "^1.1.1",
Expand All @@ -52,22 +52,22 @@
"@ethereumjs/config-tslint": "^1.1.1",
"@types/lru-cache": "^5.1.0",
"@types/node": "^11.13.4",
"@types/tape": "^4.2.33",
"browserify": "^16.2.3",
"@types/tape": "^4.13.0",
"browserify": "^16.5.1",
"istanbul": "^0.4.1",
"karma": "^4.1.0",
"karma-browserify": "^6.0.0",
"karma-chrome-launcher": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-tap": "^4.1.4",
"nyc": "^14.0.0",
"prettier": "^1.17.0",
"tape": "^4.0.3",
"ts-node": "^8.0.3",
"tslint": "^5.15.0",
"prettier": "^2.0.5",
"tape": "^4.10.1",
"ts-node": "^8.8.2",
"tslint": "^5.16.0",
"typedoc": "next",
"typedoc-plugin-markdown": "^2.2.17",
"typescript": "^3.9.2",
"typescript": "^3.9.3",
"typestrict": "^1.0.2"
}
}
18 changes: 10 additions & 8 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export class Block {
serialize(rlpEncode = true) {
const raw = [
this.header.raw,
this.transactions.map(tx => tx.raw),
this.uncleHeaders.map(uh => uh.raw),
this.transactions.map((tx) => tx.raw),
this.uncleHeaders.map((uh) => uh.raw),
]

return rlpEncode ? rlp.encode(raw) : raw
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Block {
validateTransactions(stringError = false) {
const errors: string[] = []

this.transactions.forEach(function(tx, i) {
this.transactions.forEach(function (tx, i) {
const error = tx.validate(true)
if (error) {
errors.push(`${error} at tx ${i}`)
Expand Down Expand Up @@ -206,7 +206,7 @@ export class Block {
* Validates the uncle's hash
*/
validateUnclesHash(): boolean {
const raw = rlp.encode(this.uncleHeaders.map(uh => uh.raw))
const raw = rlp.encode(this.uncleHeaders.map((uh) => uh.raw))

return keccak256(raw).toString('hex') === this.header.uncleHash.toString('hex')
}
Expand All @@ -225,13 +225,15 @@ export class Block {
throw new Error('too many uncle headers')
}

const uncleHashes = this.uncleHeaders.map(header => header.hash().toString('hex'))
const uncleHashes = this.uncleHeaders.map((header) => header.hash().toString('hex'))

if (!(new Set(uncleHashes).size === uncleHashes.length)) {
throw new Error('duplicate uncles')
}

await Promise.all(this.uncleHeaders.map(async uh => this._validateUncleHeader(uh, blockchain)))
await Promise.all(
this.uncleHeaders.map(async (uh) => this._validateUncleHeader(uh, blockchain)),
)
}

/**
Expand All @@ -243,8 +245,8 @@ export class Block {
if (labeled) {
return {
header: this.header.toJSON(true),
transactions: this.transactions.map(tx => tx.toJSON(true)),
uncleHeaders: this.uncleHeaders.forEach(uh => uh.toJSON(true)),
transactions: this.transactions.map((tx) => tx.toJSON(true)),
uncleHeaders: this.uncleHeaders.forEach((uh) => uh.toJSON(true)),
}
} else {
return baToJSON(this.raw)
Expand Down
6 changes: 3 additions & 3 deletions packages/block/src/from-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function blockFromRpc(
{
header: header.toJSON(true),
transactions: [],
uncleHeaders: uncles.map(uh => blockHeaderFromRpc(uh, chainOptions).toJSON(true)),
uncleHeaders: uncles.map((uh) => blockHeaderFromRpc(uh, chainOptions).toJSON(true)),
},
chainOptions,
)
Expand All @@ -38,12 +38,12 @@ export default function blockFromRpc(

const tx = new FakeTransaction(txParams, chainOptions as TransactionOptions)
tx.from = fromAddress
tx.getSenderAddress = function() {
tx.getSenderAddress = function () {
return fromAddress
}
// override hash
const txHash = toBuffer(txParams.hash)
tx.hash = function() {
tx.hash = function () {
return txHash
}

Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/header-from-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function blockHeaderFromRpc(blockParams: any, chainOptions?: Chai
)

// override hash in case something was missing
blockHeader.hash = function() {
blockHeader.hash = function () {
return toBuffer(blockParams.hash)
}

Expand Down
12 changes: 2 additions & 10 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ export class BlockHeader {
if (this._common.hardforkGteHardfork(hardfork, 'byzantium')) {
// max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99) (EIP100)
const uncleAddend = parentBlock.header.uncleHash.equals(KECCAK256_RLP_ARRAY) ? 1 : 2
let a = blockTs
.sub(parentTs)
.idivn(9)
.ineg()
.iaddn(uncleAddend)
let a = blockTs.sub(parentTs).idivn(9).ineg().iaddn(uncleAddend)
const cutoff = new BN(-99)
// MAX(cutoff, a)
if (cutoff.cmp(a) === 1) {
Expand Down Expand Up @@ -189,11 +185,7 @@ export class BlockHeader {
}
} else if (this._common.hardforkGteHardfork(hardfork, 'homestead')) {
// 1 - (block_timestamp - parent_timestamp) // 10
let a = blockTs
.sub(parentTs)
.idivn(10)
.ineg()
.iaddn(1)
let a = blockTs.sub(parentTs).idivn(10).ineg().iaddn(1)
const cutoff = new BN(-99)
// MAX(cutoff, a)
if (cutoff.cmp(a) === 1) {
Expand Down
Loading

0 comments on commit b571b8e

Please sign in to comment.