1(window.webpackJsonp=window.webpackJsonp||[]).push([[7],{577:function(n,e,t){"use strict";t.r(e),t.d(e,"HomeEditor",(function(){return s}));var a=t(1098),o=t(0);const r=[{path:"one/contracts/Token.one.ts",content:"import {\n Address,\n Blockchain,\n constant,\n createEventNotifier,\n Hash256,\n receive,\n Fixed,\n MapStorage,\n SmartContract,\n} from '@neo-one/smart-contract';\n\nconst notifyTransfer = createEventNotifier<Address | undefined, Address | undefined, Fixed<8>>(\n 'transfer',\n 'from',\n 'to',\n 'amount',\n);\n\nexport class Token extends SmartContract {\n public readonly name = 'Eon';\n public readonly symbol = 'EON';\n public readonly decimals = 8;\n private readonly balances = MapStorage.for<Address, Fixed<8>>();\n private mutableSupply: Fixed<8> = 0;\n\n @constant\n public get totalSupply(): Fixed<8> {\n return this.mutableSupply;\n }\n\n @constant\n public balanceOf(address: Address): Fixed<8> {\n const balance = this.balances.get(address);\n\n return balance === undefined ? 0 : balance;\n }\n\n public transfer(from: Address, to: Address, amount: Fixed<8>): boolean {\n if (amount < 0) {\n throw new Error(`Amount must be greater than 0: ${amount}`);\n }\n\n if (!Address.isCaller(from)) {\n return false;\n }\n\n const fromBalance = this.balanceOf(from);\n if (fromBalance < amount) {\n return false;\n }\n\n const toBalance = this.balanceOf(to);\n this.balances.set(from, fromBalance - amount);\n this.balances.set(to, toBalance + amount);\n notifyTransfer(from, to, amount);\n\n return true;\n }\n\n @receive\n public mintTokens(): void {\n const { references, outputs } = Blockchain.currentTransaction;\n if (references.length === 0) {\n throw new Error('Invalid mintTokens');\n }\n\n const sender = references[0].address;\n\n let amount = 0;\n for (const output of outputs) {\n if (output.address.equals(this.address)) {\n if (!output.asset.equals(Hash256.NEO)) {\n throw new Error('Invalid mintTokens');\n }\n\n amount += output.value;\n }\n }\n\n this.issue(sender, amount);\n }\n\n private issue(addr: Address, amount: Fixed<8>): void {\n this.balances.set(addr, this.balanceOf(addr) + amount);\n notifyTransfer(undefined, addr, amount);\n }\n}\n",writable:!0,open:!0},{path:"one/tests/Token.test.ts",content:"import { Hash256 } from '@neo-one/client';\nimport BigNumber from 'bignumber.js';\nimport { withContracts } from '../generated/test';\n\njest.setTimeout(60000);\n\ndescribe('Token', () => {\n test('has NEP-5 properties and methods', async () => {\n await withContracts(async ({ token, accountIDs }) => {\n expect(token).toBeDefined();\n\n const toAccountID = accountIDs[0];\n\n const [name, symbol, decimals, totalSupply, initialBalance] = await Promise.all([\n token.name(),\n token.symbol(),\n token.decimals(),\n token.totalSupply(),\n token.balanceOf(toAccountID.address),\n ]);\n expect(name).toEqual('Eon');\n expect(symbol).toEqual('EON');\n expect(decimals.toNumber()).toEqual(8);\n expect(totalSupply.toNumber()).toEqual(0);\n expect(initialBalance.toNumber()).toEqual(0);\n });\n });\n\n test('allows minting tokens and transferring them', async () => {\n await withContracts(async ({ token, accountIDs, masterAccountID }) => {\n expect(token).toBeDefined();\n\n const toAccountID = accountIDs[0];\n const mintReceipt = await token.mintTokens.confirmed({\n sendTo: [\n {\n amount: new BigNumber(1_000_000),\n asset: Hash256.NEO,\n },\n ],\n });\n if (mintReceipt.result.state === 'FAULT') {\n throw new Error(mintReceipt.result.message);\n }\n\n expect(mintReceipt.result.state).toEqual('HALT');\n expect(mintReceipt.result.value).toBeUndefined();\n expect(mintReceipt.events).toHaveLength(1);\n let event = mintReceipt.events[0];\n expect(event.name).toEqual('transfer');\n if (event.name !== 'transfer') {\n throw new Error('For TS');\n }\n expect(event.parameters.from).toBeUndefined();\n expect(event.parameters.to).toEqual(masterAccountID.address);\n expect(event.parameters.amount.toNumber()).toEqual(1_000_000);\n\n let error: Error | undefined;
1\n try {\n await token.mintTokens.confirmed({\n sendTo: [\n {\n amount: new BigNumber(10),\n asset: Hash256.GAS,\n },\n ],\n });\n } catch (err) {\n error = err;\n }\n expect(error).toBeDefined();\n\n const [totalSupply, balance, toBalance] = await Promise.all([\n token.totalSupply(),\n token.balanceOf(masterAccountID.address),\n token.balanceOf(toAccountID.address),\n ]);\n expect(totalSupply.toNumber()).toEqual(1_000_000);\n expect(balance.toNumber()).toEqual(1_000_000);\n expect(toBalance.toNumber()).toEqual(0);\n\n const transferAmount = new BigNumber(5);\n const transferReceipt = await token.transfer.confirmed(\n masterAccountID.address,\n toAccountID.address,\n transferAmount,\n );\n if (transferReceipt.result.state === 'FAULT') {\n throw new Error(transferReceipt.result.message);\n }\n expect(transferReceipt.result.state).toEqual('HALT');\n expect(transferReceipt.result.value).toEqual(true);\n\n // Verify the transfer event\n expect(transferReceipt.events).toHaveLength(1);\n event = transferReceipt.events[0];\n expect(event.name).toEqual('transfer');\n if (event.name !== 'transfer') {\n throw new Error('For TS');\n }\n expect(event.parameters.from).toEqual(masterAccountID.address);\n expect(event.parameters.to).toEqual(toAccountID.address);\n expect(event.parameters.amount.toNumber()).toEqual(transferAmount.toNumber());\n\n });\n });\n});\n",writable:!0,open:!0},{path:"package.json",content:'{\n "dependencies": {\n "bignumber.js": "8.0.1"\n }\n}',writable:!1,open:!1}],s=()=>o.createElement(a.a,{id:"home",createPreviewURL:()=>"https://preview.neo-one.io",initialFiles:r,initialOptions:{preview:{enabled:!1,open:!1}},build:!0,clearFS:!0})}}]); 2//# sourceMappingURL=HomeEditor.d73be962.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.