Skip to content

Commit

Permalink
Remove blockchain from stateManager in runBlockchain tests, minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
  • Loading branch information
s1na committed Aug 28, 2018
1 parent 88c4445 commit 33cd66c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions tests/api/runBlockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const StateManager = require('../../lib/stateManager')
tape('runBlockchain', (t) => {
const blockchainDB = new Levelup('', { db: Memdown })
const blockchain = new Blockchain(blockchainDB)
const vm = { stateManager: new StateManager({ blockchain }) }
const vm = { stateManager: new StateManager(), blockchain }

const putGenesisP = promisify(blockchain.putGenesis.bind(blockchain))
const putBlockP = promisify(blockchain.putBlock.bind(blockchain))
Expand Down Expand Up @@ -65,30 +65,24 @@ tape('runBlockchain', (t) => {
let head = await getHeadP()
st.deepEqual(head.hash(), b3.hash(), 'block3 should be the current head')

await runBlockchainP(blockchain)

head = await getHeadP()
st.deepEqual(head.hash(), b2.hash(), 'should have removed invalid block from head')
try {
await runBlockchainP(blockchain)
st.fail('should have returned error')
} catch (e) {
st.equal(e.message, 'test')

st.end()
})
})
head = await getHeadP()
st.deepEqual(head.hash(), b2.hash(), 'should have removed invalid block from head')

tape('runBlockchain with fake blockchain', (t) => {
const vm = {
stateManager: new StateManager()
}
const runBlockchainP = promisify(runBlockchain.bind(vm))

t.test('should run without errors', async (st) => {
await runBlockchainP()
st.end()
st.end()
}
})
})

function createGenesis () {
const genesis = new Block()
genesis.setGenesisParams()
return genesis
}

function createBlock (parent = null, n = 0) {
Expand Down

0 comments on commit 33cd66c

Please sign in to comment.