Skip to content

Commit

Permalink
Create test-data-feed.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 8, 2024
1 parent fbd0d9f commit f18699b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions projects/oracle-nexus/tests/unit-tests/test-data-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { expect } = require('chai');
const { ethers } = require('hardhat');

describe('DataFeed', () => {
let dataFeed;
let dataSource1;
let dataSource2;

beforeEach(async () => {
[dataSource1, dataSource2] = await ethers.getSigners();
const DataFeed = await ethers.getContractFactory('DataFeed');
dataFeed = await DataFeed.deploy();
await dataFeed.deployed();
});

it('should deploy DataFeed contract', async () => {
expect(dataFeed.address).to.not.be.undefined;
});

it('should allow data sources to push data', async () => {
await dataFeed.connect(dataSource1).pushData('0x123456');
expect(await dataFeed.getLatestData()).to.equal('0x123456');
await dataFeed.connect(dataSource2).pushData('0x789012');
expect(await dataFeed.getLatestData()).to.equal('0x789012');
});

it('should allow data sources to be added and removed', async () => {
await dataFeed.connect(dataSource1).addDataSource();
expect(await dataFeed.getDataSources()).to.include(dataSource1.address);
await dataFeed.connect(dataSource1).removeDataSource();
expect(await dataFeed.getDataSources()).to.not.include(dataSource1.address);
});

it('should allow historical data to be retrieved', async () => {
await dataFeed.connect(dataSource1).pushData('0x123456');
await dataFeed.connect(dataSource2).pushData('0x789012');
expect(await dataFeed.getHistoricalData(1)).to.equal('0x123456');
});
});

0 comments on commit f18699b

Please sign in to comment.