-
-
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
39 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,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'); | ||
}); | ||
}); |