From c1a16582ae591902bbaf0b8f66dab437d4fa2015 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Tue, 16 Jul 2024 16:23:43 +0530 Subject: [PATCH] feat: added tests for enable() --- packages/oft-sand/test/fixtures.ts | 4 ++ packages/oft-sand/test/oftSand.test.ts | 52 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/packages/oft-sand/test/fixtures.ts b/packages/oft-sand/test/fixtures.ts index bffc2c928a..220579c904 100644 --- a/packages/oft-sand/test/fixtures.ts +++ b/packages/oft-sand/test/fixtures.ts @@ -4,6 +4,7 @@ export async function setupOFTSand() { const [ executionAdmin, sandAdmin, + oftAdapterAdmin, oftAdapterOwner, oftSandOwner, oftSandOwner2, @@ -41,6 +42,7 @@ export async function setupOFTSand() { EndpointForAdapter, oftAdapterOwner, TrustedForwarder, + oftAdapterAdmin, ); const OFTSandFactoy = await ethers.getContractFactory('OFTSand'); @@ -130,7 +132,9 @@ export async function setupOFTSand() { eidOFTSand, eidOFTSand2, oftSandOwner, + sandAdmin, oftAdapterOwner, + oftAdapterAdmin, user1, user2, user3, diff --git a/packages/oft-sand/test/oftSand.test.ts b/packages/oft-sand/test/oftSand.test.ts index 9686e2aed1..452f38b3f0 100644 --- a/packages/oft-sand/test/oftSand.test.ts +++ b/packages/oft-sand/test/oftSand.test.ts @@ -24,26 +24,32 @@ describe('OFT Contracts', function () { expect(await OFTSand.getTrustedForwarder()).to.be.equal(ZeroAddress); }); - it('only OFTSand owner can enable or disable the send function', async function () { + it('only OFTSand admin can enable or disable the send function', async function () { const {OFTSand, user1} = await loadFixture(setupOFTSand); expect(await OFTSand.enabled()).to.be.true; - await expect(OFTSand.connect(user1).enable(false)) - .to.be.revertedWithCustomError(OFTSand, 'OwnableUnauthorizedAccount') - .withArgs(user1.address); + await expect( + OFTSand.connect(user1).enable(false), + ).to.be.revertedWithCustomError(OFTSand, 'OnlyAdmin'); }); - it('OFTSand owner can enable or disable the send function', async function () { - const {OFTSand, oftSandOwner} = await loadFixture(setupOFTSand); + it('OFTSand admin can enable or disable the send function', async function () { + const {OFTSand, sandAdmin} = await loadFixture(setupOFTSand); expect(await OFTSand.enabled()).to.be.true; - await OFTSand.connect(oftSandOwner).enable(false); + await OFTSand.connect(sandAdmin).enable(false); expect(await OFTSand.enabled()).to.be.false; - await OFTSand.connect(oftSandOwner).enable(true); + await OFTSand.connect(sandAdmin).enable(true); expect(await OFTSand.enabled()).to.be.true; }); + it('should emit StateChanged event for OFTSand', async function () { + const {OFTSand, sandAdmin} = await loadFixture(setupOFTSand); + const tx = await OFTSand.connect(sandAdmin).enable(false); + await expect(tx).to.emit(OFTSand, 'StateChanged').withArgs(false); + }); + it('should return false for approvalRequired', async function () { const {OFTSand} = await loadFixture(setupOFTSand); expect(await OFTSand.approvalRequired()).to.equal(false); @@ -79,24 +85,30 @@ describe('OFT Contracts', function () { expect(await OFTAdapter.getTrustedForwarder()).to.be.equal(ZeroAddress); }); - it('only OFTAdapter owner can enable or disable the send function', async function () { + it('only OFTAdapter admin can enable or disable the send function', async function () { const {OFTAdapter, user1} = await loadFixture(setupOFTSand); expect(await OFTAdapter.enabled()).to.be.true; - await expect(OFTAdapter.connect(user1).enable(false)) - .to.be.revertedWithCustomError(OFTAdapter, 'OwnableUnauthorizedAccount') - .withArgs(user1.address); + await expect( + OFTAdapter.connect(user1).enable(false), + ).to.be.revertedWithCustomError(OFTAdapter, 'OnlyAdmin'); }); - it('OFTAdapter owner can enable or disable the send function', async function () { - const {OFTAdapter, oftAdapterOwner} = await loadFixture(setupOFTSand); + it('OFTAdapter admin can enable or disable the send function', async function () { + const {OFTAdapter, oftAdapterAdmin} = await loadFixture(setupOFTSand); expect(await OFTAdapter.enabled()).to.be.true; - await OFTAdapter.connect(oftAdapterOwner).enable(false); + await OFTAdapter.connect(oftAdapterAdmin).enable(false); expect(await OFTAdapter.enabled()).to.be.false; - await OFTAdapter.connect(oftAdapterOwner).enable(true); + await OFTAdapter.connect(oftAdapterAdmin).enable(true); expect(await OFTAdapter.enabled()).to.be.true; }); + + it('should emit StateChanged event for OFTAdapter', async function () { + const {OFTAdapter, oftAdapterAdmin} = await loadFixture(setupOFTSand); + const tx = await OFTAdapter.connect(oftAdapterAdmin).enable(false); + await expect(tx).to.emit(OFTAdapter, 'StateChanged').withArgs(false); + }); }); describe('token transfer using send', function () { @@ -129,11 +141,11 @@ describe('OFT Contracts', function () { }); it('should not transfer ERC20 tokens from OFTAdapter when send function is disabled', async function () { - const {OFTAdapter, oftAdapterOwner, user1, eidOFTSand} = + const {OFTAdapter, oftAdapterAdmin, user1, eidOFTSand} = await loadFixture(setupOFTSand); // disable send() in OFTAdapter - await OFTAdapter.connect(oftAdapterOwner).enable(false); + await OFTAdapter.connect(oftAdapterAdmin).enable(false); expect(await OFTAdapter.enabled()).to.be.false; const decimalConversionRate = await OFTAdapter.decimalConversionRate(); @@ -281,7 +293,7 @@ describe('OFT Contracts', function () { OFTAdapter, OFTSand, SandMock, - oftSandOwner, + sandAdmin, user1, user2, user3, @@ -326,7 +338,7 @@ describe('OFT Contracts', function () { expect(await OFTSand.balanceOf(user2)).to.be.equal(tokensToSend); // disable send() in OFTSand - await OFTSand.connect(oftSandOwner).enable(false); + await OFTSand.connect(sandAdmin).enable(false); expect(await OFTSand.enabled()).to.be.false; const sendParam2 = [