Skip to content

Commit

Permalink
Test cases for updating ThreatOracle address
Browse files Browse the repository at this point in the history
  • Loading branch information
RCantu92 committed Dec 4, 2023
1 parent d4ed4af commit 8f24142
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scripts/deployments/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ async function migrate(config = {}) {

const minConfidenceScore = 90;
const maxAddressArgumentAmount = 50;
const managerAddress = (await ethers.getSigners())[1];

contracts.oracleConsumer = await contractHelpers.tryFetchContract(
hre,
'MockThreatOracleConsumer',
[contracts.threatOracle.address, minConfidenceScore, maxAddressArgumentAmount],
[contracts.threatOracle.address, minConfidenceScore, maxAddressArgumentAmount, managerAddress.address],
CACHE
);

Expand Down
29 changes: 29 additions & 0 deletions test/components/threat.oracle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,33 @@ describe('Threat Oracle', async function () {
.to.be.revertedWith(`${MaxAddressArgumentAmountExceededSig}`);
});
});

describe.only('mock app suite', async function () {
it('allows contract owner to update the address for the ThreatOracle', async function () {
expect(await this.oracleConsumer.connect(this.accounts.user1).getThreatOracleAddress()).to.be.equal(this.threatOracle.address);

await expect(this.oracleConsumer.connect(this.accounts.manager).updateThreatOracleContractAddress(mockAccounts[0]))
.to.emit(this.oracleConsumer, 'ThreatOracleContractUpdated')
.withArgs(this.threatOracle.address, mockAccounts[0]);

expect(await this.oracleConsumer.connect(this.accounts.user1).getThreatOracleAddress()).to.be.equal(mockAccounts[0]);

// Change it back
await expect(this.oracleConsumer.connect(this.accounts.manager).updateThreatOracleContractAddress(this.threatOracle.address))
.to.emit(this.oracleConsumer, 'ThreatOracleContractUpdated')
.withArgs(mockAccounts[0], this.threatOracle.address);

expect(await this.oracleConsumer.connect(this.accounts.user1).getThreatOracleAddress()).to.be.equal(this.threatOracle.address);
});

it.only('blocks non-owner accounts from updating the address for the ThreatOracle', async function () {
expect(await this.oracleConsumer.connect(this.accounts.user1).getThreatOracleAddress()).to.be.equal(this.threatOracle.address);

await expect(this.oracleConsumer.connect(this.accounts.other).updateThreatOracleContractAddress(mockAccounts[0]))
.to.be.revertedWith(`MsgSenderNotOwner("${this.accounts.other.address}")`);

// Confirm it wasn't changed
expect(await this.oracleConsumer.connect(this.accounts.user1).getThreatOracleAddress()).to.be.equal(this.threatOracle.address);
});
});
})

0 comments on commit 8f24142

Please sign in to comment.