From 305b31b72fe4209f72991aa210e02f78500acb71 Mon Sep 17 00:00:00 2001 From: velitchko Date: Wed, 29 May 2024 16:31:03 +0200 Subject: [PATCH] Test implementation for (in-)sufficient funds provided --- test/ERC4908Example.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/ERC4908Example.ts b/test/ERC4908Example.ts index 8a9bde4..a7e950d 100644 --- a/test/ERC4908Example.ts +++ b/test/ERC4908Example.ts @@ -141,6 +141,42 @@ describe("ERC4908", function () { ); await expect(mintAvailableContent).to.be.fulfilled; }); + + it("Should check if the expected NFT price is met", async function () { + + /* Arrange */ + + const { erc4908Example, wallets } = await loadFixture(deployERC4908ExampleFixture); + const { contentId, price, expirationTime } = paramsDefault; + const [Alice, Bob] = wallets; + + let alice = await impersonate(erc4908Example, Alice); + let bob = await impersonate(erc4908Example, Bob); + + await alice.write.setAccess([contentId, price, expirationTime]); + + /* Act */ + + const mintInsufficientFunds = bob.write.mint([ + Alice.account.address, + contentId, + Bob.account.address + ], { value: price - 1n}) + + const mintSufficientFunds = bob.write.mint([ + Alice.account.address, + contentId, + Bob.account.address + ], { value: price }) + + + /* Assert */ + + await expect(mintInsufficientFunds).to.be.rejectedWith( + 'InsufficientFunds(2)' + ); + await expect(mintSufficientFunds).to.be.fulfilled; + }); }); describe("Resources access check", function () {