Skip to content

Commit

Permalink
Test OwnerBurn fails while not enough balance to burn
Browse files Browse the repository at this point in the history
  • Loading branch information
ninokeldishvili committed Jul 11, 2024
1 parent 54116ca commit 2e07228
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 53 deletions.
44 changes: 40 additions & 4 deletions test/foundry/src/concrete/receipt/Receipt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ contract ReceiptTest is Test {
assertEq(owner, alice);
}

/// test receipt OwnerMint function
function testOwnerMint(uint256 fuzzedKeyAlice, uint256 id, uint256 amount, bytes memory data) public {
/// Test receipt OwnerMint function
function testOwnerMint(uint256 fuzzedKeyAlice, uint256 id, uint256 amount, bytes memory data) external {
// Ensure the fuzzed key is within the valid range for secp256
address alice = vm.addr((fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1);
amount = bound(amount, 1, type(uint256).max);
Expand All @@ -64,8 +64,8 @@ contract ReceiptTest is Test {
assertEq(receipt.balanceOf(alice, id), amount);
}

/// test receipt OwnerBurn function
function testOwnerBurn(uint256 fuzzedKeyAlice, uint256 id, uint256 amount, uint256 fuzzedReceiptSeed) public {
/// Test receipt OwnerBurn function
function testOwnerBurn(uint256 fuzzedKeyAlice, uint256 id, uint256 amount, uint256 fuzzedReceiptSeed) external {
// Ensure the fuzzed key is within the valid range for secp256
address alice = vm.addr((fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1);
amount = bound(amount, 1, type(uint256).max);
Expand Down Expand Up @@ -99,4 +99,40 @@ contract ReceiptTest is Test {
// Check the balance of the minted tokens
assertEq(receipt.balanceOf(alice, id), 0);
}

/// Test OwnerBurn fails while not enough balance to burn
function testOwnerBurnNoTEnoughBalance(
uint256 fuzzedKeyAlice,
uint256 id,
uint256 amount,
bytes memory fuzzedReceiptInformation,
uint256 burnAmount
) external {
// Ensure the fuzzed key is within the valid range for secp256
address alice = vm.addr((fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1);
// Bound with uint256 max - 1 so dowsnot get overflow while bounding burnAmount
amount = bound(amount, 1, type(uint256).max - 1);
id = bound(id, 0, type(uint256).max);

TestReceipt receipt = new TestReceipt();
TestReceiptOwner receiptOwner = new TestReceiptOwner();

// Set the receipt owner
receipt.setOwner(address(receiptOwner));

// Set the authorized 'from' and 'to' addresses in receiptOwner
receiptOwner.setFrom(address(0));
receiptOwner.setTo(alice);

vm.startPrank(alice);
receiptOwner.ownerMint(receipt, alice, id, amount, fuzzedReceiptInformation);
uint256 receiptBalance = receipt.balanceOf(alice, id);
burnAmount = bound(burnAmount, receiptBalance + 1, type(uint256).max);

receiptOwner.setFrom(alice);
receiptOwner.setTo(address(0));

vm.expectRevert();
receiptOwner.ownerBurn(receipt, alice, id, burnAmount, fuzzedReceiptInformation);
}
}
49 changes: 0 additions & 49 deletions test/receipt/Receipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,6 @@ import { ReceiptInformationEvent } from "../../typechain-types/contracts/vault/r
const assert = require("assert");

describe("Receipt vault", async function () {
it("OwnerBurn fails while not enough balance to burn", async function () {
const signers = await ethers.getSigners();
const alice = signers[0];

const testErc20 = await ethers.getContractFactory("TestErc20");
const asset = (await testErc20.deploy()) as TestErc20;
await asset.deployed();

const testReceipt = await ethers.getContractFactory("TestReceipt");
const receipt = (await testReceipt.deploy()) as TestReceipt;
await receipt.deployed();

const testReceiptOwner = await ethers.getContractFactory(
"TestReceiptOwner"
);
const receiptOwner = (await testReceiptOwner.deploy()) as TestReceiptOwner;
await receiptOwner.deployed();

await receipt.setOwner(receiptOwner.address);

const assets = ethers.BigNumber.from(30);
await asset.transfer(alice.address, assets);
await asset.connect(alice).increaseAllowance(receiptOwner.address, assets);

await receiptOwner.setFrom(ADDRESS_ZERO);
await receiptOwner.setTo(alice.address);

const receiptId = ethers.BigNumber.from(1);
const toMint = ethers.BigNumber.from(10);
await receiptOwner
.connect(alice)
.ownerMint(receipt.address, alice.address, receiptId, toMint, []);

await receiptOwner.setFrom(alice.address);
await receiptOwner.setTo(ADDRESS_ZERO);

const balanceBefore = await receipt.balanceOf(alice.address, receiptId);

const toBurn = balanceBefore.add(1);

await assertError(
async () =>
await receiptOwner
.connect(alice)
.ownerBurn(receipt.address, alice.address, receiptId, toBurn, []),
"ERC1155: burn amount exceeds balance",
"failed to prevent ownerBurn"
);
});
it("OwnerTransferFrom more than balance", async function () {
const signers = await ethers.getSigners();
const alice = signers[0];
Expand Down

0 comments on commit 2e07228

Please sign in to comment.