fixing more tests
This commit is contained in:
parent
177cf9ac25
commit
81a8b58c9a
@ -28,7 +28,7 @@ describe('BlockService', function() {
|
|||||||
describe('getBlock', function() {
|
describe('getBlock', function() {
|
||||||
|
|
||||||
var mockRpc, transactionMock, database, blockService;
|
var mockRpc, transactionMock, database, blockService;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
database = sinon.mock();
|
database = sinon.mock();
|
||||||
mockRpc = sinon.mock();
|
mockRpc = sinon.mock();
|
||||||
@ -43,7 +43,7 @@ describe('BlockService', function() {
|
|||||||
height: 2,
|
height: 2,
|
||||||
version: 1,
|
version: 1,
|
||||||
merkleroot: '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5',
|
merkleroot: '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5',
|
||||||
tx: [ '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5' ],
|
tx: ['9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5'],
|
||||||
time: 1231469744,
|
time: 1231469744,
|
||||||
nonce: 1639830024,
|
nonce: 1639830024,
|
||||||
bits: '1d00ffff',
|
bits: '1d00ffff',
|
||||||
@ -63,7 +63,7 @@ describe('BlockService', function() {
|
|||||||
transactionService: transactionMock,
|
transactionService: transactionMock,
|
||||||
database: database
|
database: database
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves correctly a block, uses RPC', function(callback) {
|
it('retrieves correctly a block, uses RPC', function(callback) {
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ describe('BlockService', function() {
|
|||||||
var genesisBlock = require('../data/genesis');
|
var genesisBlock = require('../data/genesis');
|
||||||
var block169 = require('../data/169');
|
var block169 = require('../data/169');
|
||||||
var block170 = require('../data/170');
|
var block170 = require('../data/170');
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
database = sinon.mock();
|
database = sinon.mock();
|
||||||
mockRpc = sinon.mock();
|
mockRpc = sinon.mock();
|
||||||
@ -102,52 +102,66 @@ describe('BlockService', function() {
|
|||||||
database: database
|
database: database
|
||||||
});
|
});
|
||||||
blockService.writeLock = sinon.mock();
|
blockService.writeLock = sinon.mock();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('makes the expected calls when confirming the genesis block', function(callback) {
|
it('makes the expected calls when confirming the genesis block', function(callback) {
|
||||||
database.batchAsync = function(ops) {
|
database.batchAsync = function(ops) {
|
||||||
ops.should.deep.equal([
|
var expectedOps = [{
|
||||||
{ type: 'put',
|
type: 'put',
|
||||||
key: 'nxt-0000000000000000000000000000000000000000000000000000000000000000',
|
key: 'nxt-0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' },
|
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
||||||
{ type: 'put',
|
}, {
|
||||||
key: 'prev-000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
type: 'put',
|
||||||
value: '0000000000000000000000000000000000000000000000000000000000000000' },
|
key: 'prev-000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
||||||
{ type: 'put',
|
value: '0000000000000000000000000000000000000000000000000000000000000000'
|
||||||
key: 'bh-000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
}, {
|
||||||
value: 0 },
|
type: 'put',
|
||||||
{ type: 'put',
|
key: 'bh-000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
||||||
key: 'bts-1231006505',
|
value: 0
|
||||||
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' }
|
}, {
|
||||||
]);
|
type: 'put',
|
||||||
|
key: 'bts-1231006505',
|
||||||
|
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
||||||
|
}, {
|
||||||
|
type: 'put',
|
||||||
|
key: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
||||||
|
}];
|
||||||
|
console.log(ops);
|
||||||
|
console.log(expectedOps);
|
||||||
|
ops.should.deep.equal(expectedOps);
|
||||||
return thenCaller;
|
return thenCaller;
|
||||||
};
|
};
|
||||||
blockService.unlock = callback;
|
blockService.unlock = callback;
|
||||||
blockService.writeLock.onFirstCall().returns(thenCaller);
|
blockService.writeLock.onFirstCall().returns(thenCaller);
|
||||||
blockService.getBlock = sinon.mock();
|
blockService.getBlock = sinon.mock();
|
||||||
database.getAsync = function() {
|
database.getAsync = function() {
|
||||||
return Promise.reject({notFound: true});
|
return Promise.reject({
|
||||||
|
notFound: true
|
||||||
|
});
|
||||||
};
|
};
|
||||||
transactionMock._confirmTransaction = sinon.mock();
|
transactionMock._confirmTransaction = sinon.mock();
|
||||||
blockService._confirmBlock(genesisBlock);
|
blockService.confirm(genesisBlock);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('makes the expected calls when confirming the block #170', function(callback) {
|
it('makes the expected calls when confirming the block #170', function(callback) {
|
||||||
database.batchAsync = function(ops) {
|
database.batchAsync = function(ops) {
|
||||||
ops.should.deep.equal([
|
ops.should.deep.equal([{
|
||||||
{ type: 'put',
|
type: 'put',
|
||||||
key: 'nxt-000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55',
|
key: 'nxt-000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55',
|
||||||
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee' },
|
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee'
|
||||||
{ type: 'put',
|
}, {
|
||||||
key: 'prev-00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee',
|
type: 'put',
|
||||||
value: '000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55' },
|
key: 'prev-00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee',
|
||||||
{ type: 'put',
|
value: '000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55'
|
||||||
key: 'bh-00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee',
|
}, {
|
||||||
value: 170 },
|
type: 'put',
|
||||||
{ type: 'put',
|
key: 'bh-00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee',
|
||||||
key: 'bts-1231731025',
|
value: 170
|
||||||
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee' }
|
}, {
|
||||||
]);
|
type: 'put',
|
||||||
|
key: 'bts-1231731025',
|
||||||
|
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee'
|
||||||
|
}]);
|
||||||
return thenCaller;
|
return thenCaller;
|
||||||
};
|
};
|
||||||
blockService.unlock = callback;
|
blockService.unlock = callback;
|
||||||
@ -156,7 +170,9 @@ describe('BlockService', function() {
|
|||||||
return Promise.resolve(block169);
|
return Promise.resolve(block169);
|
||||||
};
|
};
|
||||||
database.getAsync = function() {
|
database.getAsync = function() {
|
||||||
return Promise.reject({notFound: true});
|
return Promise.reject({
|
||||||
|
notFound: true
|
||||||
|
});
|
||||||
};
|
};
|
||||||
transactionMock._confirmTransaction = sinon.spy();
|
transactionMock._confirmTransaction = sinon.spy();
|
||||||
blockService._confirmBlock(block170);
|
blockService._confirmBlock(block170);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user