Skip to content

Commit

Permalink
Create BlockchainService.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 11, 2024
1 parent b9708a9 commit a573032
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pi-nexus-blockchain/tests/unit/BlockchainService.test.js
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);
});
});

0 comments on commit a573032

Please sign in to comment.