Skip to content

Commit

Permalink
test: add extreme case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Aug 22, 2024
1 parent e319f7e commit 16db798
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/lsp26-contracts/contracts/mock/ReturnBomb.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.17;

// interfaces
import {
ILSP1UniversalReceiver
} from "@lukso/lsp1-contracts/contracts/ILSP1UniversalReceiver.sol";

contract ReturnBomb is ILSP1UniversalReceiver {
uint256 public counter;

function supportsInterface(bytes4) external pure returns (bool) {
return true;
}

function universalReceiver(
bytes32,
bytes memory
) external payable returns (bytes memory) {
++counter;
// solhint-disable-next-line no-inline-assembly
assembly {
revert(0, 10000)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.17;

// interfaces
import {
ILSP1UniversalReceiver
} from "@lukso/lsp1-contracts/contracts/ILSP1UniversalReceiver.sol";

contract SelfDestructOnInterfaceCheck is ILSP1UniversalReceiver {
uint256 public counter;

function supportsInterface(bytes4) external returns (bool) {
selfdestruct(payable(msg.sender));
return true;
}

function universalReceiver(
bytes32,
bytes memory
) external payable returns (bytes memory) {
return "";
}
}
64 changes: 64 additions & 0 deletions packages/lsp26-contracts/tests/LSP26FollowerSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
LSP0ERC725Account__factory,
RevertOnFollow__factory,
RevertOnFollow,
ReturnBomb__factory,
ReturnBomb,
SelfDestructOnInterfaceCheck__factory,
SelfDestructOnInterfaceCheck,
} from '../types';

describe('testing `LSP26FollowerSystem`', () => {
Expand Down Expand Up @@ -115,6 +119,66 @@ describe('testing `LSP26FollowerSystem`', () => {
});
});

describe('testing following/unfollowing a contract that self destructs on interface check', async () => {
let selfDestruct: SelfDestructOnInterfaceCheck;

before(async () => {
selfDestruct = await new SelfDestructOnInterfaceCheck__factory(context.owner).deploy();
});

it('should pass following', async () => {
await context.followerSystem.connect(context.owner).follow(await selfDestruct.getAddress());

expect(
await context.followerSystem.isFollowing(
context.owner.address,
await selfDestruct.getAddress(),
),
).to.be.true;
});

it('should pass unfollowing', async () => {
await context.followerSystem.connect(context.owner).unfollow(await selfDestruct.getAddress());

expect(
await context.followerSystem.isFollowing(
context.owner.address,
await selfDestruct.getAddress(),
),
).to.be.false;
});
});

describe('testing following/unfollowing a contract with return bomb', () => {
let returnBomb: ReturnBomb;

before(async () => {
returnBomb = await new ReturnBomb__factory(context.owner).deploy();
});

it('should pass following', async () => {
await context.followerSystem.connect(context.owner).follow(await returnBomb.getAddress());

expect(
await context.followerSystem.isFollowing(
context.owner.address,
await returnBomb.getAddress(),
),
).to.be.true;
});

it('should pass unfollowing', async () => {
await context.followerSystem.connect(context.owner).unfollow(await returnBomb.getAddress());

expect(
await context.followerSystem.isFollowing(
context.owner.address,
await returnBomb.getAddress(),
),
).to.be.false;
});
});

describe.skip('gas tests', () => {
const gasCostResult: {
followingGasCost?: number[];
Expand Down

0 comments on commit 16db798

Please sign in to comment.