Skip to content

Commit

Permalink
feat: added tests for enable()
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Jul 16, 2024
1 parent 70fbaaa commit c1a1658
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/oft-sand/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export async function setupOFTSand() {
const [
executionAdmin,
sandAdmin,
oftAdapterAdmin,
oftAdapterOwner,
oftSandOwner,
oftSandOwner2,
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function setupOFTSand() {
EndpointForAdapter,
oftAdapterOwner,
TrustedForwarder,
oftAdapterAdmin,
);

const OFTSandFactoy = await ethers.getContractFactory('OFTSand');
Expand Down Expand Up @@ -130,7 +132,9 @@ export async function setupOFTSand() {
eidOFTSand,
eidOFTSand2,
oftSandOwner,
sandAdmin,
oftAdapterOwner,
oftAdapterAdmin,
user1,
user2,
user3,
Expand Down
52 changes: 32 additions & 20 deletions packages/oft-sand/test/oftSand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -281,7 +293,7 @@ describe('OFT Contracts', function () {
OFTAdapter,
OFTSand,
SandMock,
oftSandOwner,
sandAdmin,
user1,
user2,
user3,
Expand Down Expand Up @@ -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 = [
Expand Down

1 comment on commit c1a1658

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

91.11%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/oft-sand/contracts
   OFTAdapterForSand.sol92%100%85.71%91.67%72
   OFTSand.sol94.12%100%90.91%94.12%120
packages/oft-sand/contracts/interfaces
   IERC20Extended.sol100%100%100%100%
   IErrors.sol100%100%100%100%
packages/oft-sand/contracts/mock
   EndpointMock.sol100%100%100%100%
   MockTrustedForwarder.sol100%100%100%100%
   SandMock.sol100%100%100%100%
packages/oft-sand/contracts/oft/libraries
   OFTMsgCodec.sol70.59%50%71.43%75%27, 64, 73
packages/oft-sand/contracts/sand
   ERC20Internal.sol100%100%100%100%
   SandBaseToken.sol100%100%100%100%

Please sign in to comment.