From f840ac60bef8e0d0a6a8a82d3be7c67b7d6d1b4b Mon Sep 17 00:00:00 2001 From: Jawad Tariq Date: Wed, 2 Aug 2023 17:02:52 -0400 Subject: [PATCH] feat: add AC to pushCertificate Signed-off-by: Jawad Tariq --- contracts/topos-core/ToposCore.sol | 2 +- test/topos-core/ToposCore.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/contracts/topos-core/ToposCore.sol b/contracts/topos-core/ToposCore.sol index 075d7ff..8bfce84 100644 --- a/contracts/topos-core/ToposCore.sol +++ b/contracts/topos-core/ToposCore.sol @@ -67,7 +67,7 @@ contract ToposCore is IToposCore, AdminMultisigBase { /// @notice Push the certificate on-chain /// @param certBytes The certificate in byte /// @param position The position of the certificate - function pushCertificate(bytes memory certBytes, uint256 position) external override { + function pushCertificate(bytes memory certBytes, uint256 position) external override onlyAdmin { ( CertificateId prevId, SubnetId sourceSubnetId, diff --git a/test/topos-core/ToposCore.test.ts b/test/topos-core/ToposCore.test.ts index 7e03b28..a2dd45a 100644 --- a/test/topos-core/ToposCore.test.ts +++ b/test/topos-core/ToposCore.test.ts @@ -48,6 +48,16 @@ describe('ToposCore', () => { ).to.be.revertedWith('Bytes32Set: key already exists in the set.') }) + it('reverts if non-admin tries to push certificate', async () => { + const { defaultCert, toposCore } = await loadFixture( + deployToposCoreFixture + ) + const [, nonAdmin] = await ethers.getSigners() + await expect( + toposCore.connect(nonAdmin).pushCertificate(defaultCert, cc.CERT_POS_1) + ).to.be.revertedWithCustomError(toposCore, 'NotAdmin') + }) + it('gets the certificate count', async () => { const { defaultCert, toposCore } = await loadFixture( deployToposCoreFixture