diff --git a/test/foundry/src/concrete/receipt/Receipt.t.sol b/test/foundry/src/concrete/receipt/Receipt.t.sol index af0bd8d4..86baf22a 100644 --- a/test/foundry/src/concrete/receipt/Receipt.t.sol +++ b/test/foundry/src/concrete/receipt/Receipt.t.sol @@ -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); @@ -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); @@ -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); + } } diff --git a/test/receipt/Receipt.test.ts b/test/receipt/Receipt.test.ts index 80170766..eaf4be8e 100644 --- a/test/receipt/Receipt.test.ts +++ b/test/receipt/Receipt.test.ts @@ -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];