-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { BlockchainService } from '../../src/services/BlockchainService'; | ||
import { BlockchainModel } from '../../src/models/BlockchainModel'; | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
|
||
describe('BlockchainService', () => { | ||
let blockchainService; | ||
let blockchainModelStub; | ||
|
||
beforeEach(() => { | ||
blockchainModelStub = sinon.stub(BlockchainModel, 'findOne'); | ||
blockchainService = new BlockchainService(); | ||
}); | ||
|
||
afterEach(() => { | ||
blockchainModelStub.restore(); | ||
}); | ||
|
||
it('should get blockchain by networkId', async () => { | ||
const networkId = 'mainnet'; | ||
const blockchain = { id: 1, networkId, chainId: '1' }; | ||
blockchainModelStub.resolves(blockchain); | ||
|
||
const result = await blockchainService.getBlockchainByNetworkId(networkId); | ||
expect(result).to.deep.equal(blockchain); | ||
}); | ||
|
||
it('should update blockchain block number', async () => { | ||
const blockchain = { id: 1, networkId: 'mainnet', chainId: '1', blockNumber: 100 }; | ||
blockchainModelStub.resolves(blockchain); | ||
|
||
const newBlockNumber = 150; | ||
await blockchainService.updateBlockchainBlockNumber(blockchain.id, newBlockNumber); | ||
expect(blockchain.blockNumber).to.equal(newBlockNumber); | ||
}); | ||
}); |