From 8f2414232364a34207a5da2599c9817b8c74fba7 Mon Sep 17 00:00:00 2001 From: Roberto Cantu Date: Mon, 4 Dec 2023 15:43:02 -0600 Subject: [PATCH] Test cases for updating ThreatOracle address --- scripts/deployments/platform.js | 4 +++- test/components/threat.oracle.test.js | 29 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/deployments/platform.js b/scripts/deployments/platform.js index e52a75e0..f52b91d3 100644 --- a/scripts/deployments/platform.js +++ b/scripts/deployments/platform.js @@ -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 ); diff --git a/test/components/threat.oracle.test.js b/test/components/threat.oracle.test.js index d88d68ca..73c23489 100644 --- a/test/components/threat.oracle.test.js +++ b/test/components/threat.oracle.test.js @@ -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); + }); + }); }) \ No newline at end of file