Skip to content

Commit

Permalink
update use of setHardfork to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Jul 19, 2021
1 parent 1dfd049 commit c39c82a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ tape('[Block]: block functions', function (t) {
const blockchain = new Mockchain()

const common = new Common({ chain: Chain.Mainnet })
common.setHardfork('berlin')
common.setHardfork(Hardfork.Berlin)

const mainnetForkBlock = common.hardforkBlockBN('london')
const rootBlock = Block.fromBlockData({
Expand All @@ -491,7 +491,7 @@ tape('[Block]: block functions', function (t) {
common
)
await blockchain.putBlock(preForkBlock)
common.setHardfork('london')
common.setHardfork(Hardfork.London)
const forkBlock = createBlock(preForkBlock, 'forkBlock', [], common)
await blockchain.putBlock(forkBlock)
const uncleFork = createBlock(forkBlock, 'uncleFork', [], common)
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tape('[Block]: Header functions', function (t) {
st.ok(header.hash().toString('hex'), 'genesis block should initialize')
st.equal(header._common.hardfork(), 'chainstart', 'should initialize with correct HF provided')

common.setHardfork('byzantium')
common.setHardfork(Hardfork.Byzantium)
st.equal(
header._common.hardfork(),
'chainstart',
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class Blockchain implements BlockchainInterface {

if (!genesisBlock) {
const common = this._common.copy()
common.setHardfork('chainstart')
common.setHardfork(Hardfork.Chainstart)
genesisBlock = Block.genesis({}, { common })
}

Expand Down
5 changes: 3 additions & 2 deletions packages/client/lib/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Hardfork } from '@ethereumjs/common'
import { Transaction, TransactionFactory } from '@ethereumjs/tx'
import {
Account,
Expand Down Expand Up @@ -471,8 +472,8 @@ export class Eth {
try {
const common = this.client.config.chainCommon.copy()
// TODO: generalize with a new Common.latestSupportedHardfork() method or similar
// Alternative: common.setHardfork('lastest')
common.setHardfork('london')
// Alternative: common.setHardfork('latest')
common.setHardfork(Hardfork.London)
const tx = TransactionFactory.fromSerializedData(toBuffer(serializedTx), { common })
if (!tx.isSigned()) {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/tests/hardforks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) {
st.equal(hardfork, 'byzantium', 'should send correct hardforkChanged event')
st.end()
})
c.setHardfork('byzantium')
c.setHardfork(Hardfork.Byzantium)
})

t.test('hardforkBlock()', function (st: tape.Test) {
Expand Down
8 changes: 4 additions & 4 deletions packages/common/tests/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ tape('[Common]: Parameter access for param(), paramByHardfork()', function (t: t
st.equal(c.paramByHardfork('gasPrices', 'ecAdd', 'byzantium'), 500, msg)

msg = 'Should return correct value for HF set in class'
c.setHardfork('byzantium')
c.setHardfork(Hardfork.Byzantium)
st.equal(c.param('gasPrices', 'ecAdd'), 500, msg)
c.setHardfork('istanbul')
c.setHardfork(Hardfork.Istanbul)
st.equal(c.param('gasPrices', 'ecAdd'), 150, msg)
c.setHardfork('muirGlacier')
c.setHardfork(Hardfork.MuirGlacier)
st.equal(c.param('gasPrices', 'ecAdd'), 150, msg)

msg = 'Should return null for non-existing value'
Expand Down Expand Up @@ -40,7 +40,7 @@ tape('[Common]: Parameter access for param(), paramByHardfork()', function (t: t
let msg = 'Should throw when called with non-existing topic'
st.throws(f, /Topic gasPrizes not defined$/, msg)

c.setHardfork('byzantium')
c.setHardfork(Hardfork.Byzantium)
st.equal(c.param('gasPrices', 'ecAdd'), 500, 'Should return correct value for HF set in class')

c = new Common({
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/test/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ tape('[BaseTransaction]', function (t) {
`${txType.name}: should initialize with correct HF provided`
)

initCommon.setHardfork('byzantium')
initCommon.setHardfork(Hardfork.Byzantium)
st.equal(
tx.common.hardfork(),
'london',
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/tests/api/opcodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ tape('VM -> getActiveOpcodes()', (t) => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const vm = new VM({ common })

common.setHardfork('byzantium')
common.setHardfork(Hardfork.Byzantium)
st.equal(
vm.getActiveOpcodes().get(CHAINID),
undefined,
'opcode not exposed after HF change (-> < istanbul)'
)

common.setHardfork('istanbul')
common.setHardfork(Hardfork.Istanbul)
st.equal(
vm.getActiveOpcodes().get(CHAINID)!.name,
'CHAINID',
Expand Down

0 comments on commit c39c82a

Please sign in to comment.