From a573032b522c6ed596b1b1126857dde87eddfb97 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 11 Aug 2024 15:30:24 +0700 Subject: [PATCH] Create BlockchainService.test.js --- .../tests/unit/BlockchainService.test.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pi-nexus-blockchain/tests/unit/BlockchainService.test.js diff --git a/pi-nexus-blockchain/tests/unit/BlockchainService.test.js b/pi-nexus-blockchain/tests/unit/BlockchainService.test.js new file mode 100644 index 000000000..28407dfe8 --- /dev/null +++ b/pi-nexus-blockchain/tests/unit/BlockchainService.test.js @@ -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); + }); +});