1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| const MultiFunctionToken = artifacts.require("MultiFunctionToken");
contract("MultiFunctionToken", accounts => { let token; const owner = accounts[0]; const user1 = accounts[1]; const user2 = accounts[2]; const user3 = accounts[3]; const initialSupply = 1000000 * 10 ** 18;
beforeEach(async () => { token = await MultiFunctionToken.new("MultiFunctionToken", "MFT"); });
it("should have correct initial supply", async () => { const totalSupply = await token.totalSupply(); assert.equal(totalSupply.toString(), "1000000000000000000000000", "Initial supply is incorrect"); });
it("should allow data storage and retrieval", async () => { const testData = "test data"; await token.storeData(testData, {from: user1}); const retrievedData = await token.getData(user1); assert.equal(retrievedData, testData, "Data storage/retrieval failed"); });
it("should transfer tokens correctly", async () => { const amount = 1000; await token.transfer(user1, amount, {from: owner}); const balance = await token.balanceOf(user1); assert.equal(balance.toString(), amount.toString(), "Token transfer failed"); });
it("should allow owner to mint new tokens", async () => { const amount = 5000; await token.mint(user2, amount, {from: owner}); const balance = await token.balanceOf(user2); assert.equal(balance.toString(), amount.toString(), "Minting failed"); });
it("should prevent non-owner from minting", async () => { try { await token.mint(user1, 1000, {from: user1}); assert.fail("Non-owner should not be able to mint"); } catch (error) { assert.include(error.message, "Only owner can call this function", "Expected owner restriction"); } });
it("should transfer ownership correctly", async () => { await token.transferOwnership(user1, {from: owner}); const newOwner = await token.owner(); assert.equal(newOwner, user1, "Ownership transfer failed"); });
it("should pause and unpause contract", async () => { await token.pause({from: owner}); let paused = true; try { await token.transfer(user1, 100, {from: owner}); } catch (error) { paused = false; } assert.equal(paused, false, "Contract should be paused");
await token.unpause({from: owner}); await token.transfer(user1, 100, {from: owner}); const balance = await token.balanceOf(user1); assert.equal(balance.toString(), "100", "Contract should be unpaused"); });
it("should manage blacklist correctly", async () => { await token.blacklist(user2, {from: owner}); let isBlacklisted = await token.isBlacklisted(user2); assert.equal(isBlacklisted, true, "User should be blacklisted");
let transferFailed = false; try { await token.transfer(user2, 100, {from: owner}); } catch (error) { transferFailed = true; } assert.equal(transferFailed, true, "Blacklisted user should not receive tokens");
await token.unblacklist(user2, {from: owner}); isBlacklisted = await token.isBlacklisted(user2); assert.equal(isBlacklisted, false, "User should be unblacklisted"); });
it("should burn tokens correctly", async () => { const initialBalance = await token.balanceOf(owner); const burnAmount = 1000; await token.burn(burnAmount, {from: owner}); const newBalance = await token.balanceOf(owner); assert.equal(newBalance.toString(), "999999999999999999999000", "Token burn failed"); });
it("should perform batch transfer", async () => { const recipients = [user1, user2, user3]; const amounts = [100, 200, 300]; await token.batchTransfer(recipients, amounts, {from: owner}); const balance1 = await token.balanceOf(user1); const balance2 = await token.balanceOf(user2); const balance3 = await token.balanceOf(user3); assert.equal(balance1.toString(), "100", "Batch transfer failed for user1"); assert.equal(balance2.toString(), "200", "Batch transfer failed for user2"); assert.equal(balance3.toString(), "300", "Batch transfer failed for user3"); });
it("should manage token URI", async () => { const testURI = "https://example.com/token-metadata.json"; await token.setTokenURI(testURI, {from: owner}); const currentURI = await token.tokenURI(); assert.equal(currentURI, testURI, "Token URI management failed"); }); });
|