Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Aug 28, 2024
1 parent cf56841 commit 2ac3295
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contracts/test/SkaleTokenInternalTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

pragma solidity 0.8.17;

import { IERC777Recipient } from "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import { SkaleToken } from "../SkaleToken.sol";
import { ISkaleTokenInterfaceTester } from "./interfaces/ISkaleTokenInterfaceTester.sol";

Expand All @@ -32,6 +33,30 @@ contract SkaleTokenInternalTester is SkaleToken, ISkaleTokenInterfaceTester {
// solhint-disable-next-line no-empty-blocks
{ }

function callTokensReceived(
address implementer,
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
external
override
{
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived({
operator: operator,
from: from,
to: to,
amount: amount,
userData: userData,
operatorData: operatorData
});
}
}

function getMsgData() external view override returns (bytes memory msgData) {
return _msgData();
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/test/interfaces/ISkaleTokenInterfaceTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ pragma solidity 0.8.17;


interface ISkaleTokenInterfaceTester {
function callTokensReceived(
address implementer,
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
external;
function getMsgData() external view returns (bytes memory msgData);
}
24 changes: 24 additions & 0 deletions test/delegation/Delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,30 @@ describe("Delegation", () => {
.should.be.eventually.rejectedWith("Limit of validators is reached");
});

it("should revert on incorrect transfers", async () => {
const skaleTokenInternalTesterFactory = await ethers.getContractFactory("SkaleTokenInternalTester");
const skaleTokenInternalTester = await skaleTokenInternalTesterFactory.deploy(contractManager, []);
await contractManager.setContractsAddress("SkaleToken", skaleTokenInternalTester);
await skaleTokenInternalTester.callTokensReceived(
distributor,
ethers.ZeroAddress,
holder1,
holder2, // Receiver always needs to be the Distributor
5,
"0x",
"0x"
).should.be.revertedWithCustomError(distributor, "ReceiverIsIncorrect");
await skaleTokenInternalTester.callTokensReceived(
distributor,
ethers.ZeroAddress,
holder1,
distributor,
5,
"0x", // Data length always must be 32 bytes
"0x"
).should.be.revertedWithCustomError(distributor, "DataLengthIsIncorrect");
})

describe("when holders have tokens and validator is registered", () => {
let validatorId: bigint;
fastBeforeEach(async () => {
Expand Down

0 comments on commit 2ac3295

Please sign in to comment.