UNPKG

@0xcert/ethereum-erc20-contracts

Version:

Smart contract implementation of the ERC-20 standard on the Ethereum blockchain.

90 lines 4.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const spec_1 = require("@specron/spec"); const spec = new spec_1.Spec(); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const accounts = yield ctx.web3.eth.getAccounts(); ctx.set('owner', accounts[0]); ctx.set('bob', accounts[1]); ctx.set('jane', accounts[2]); ctx.set('sara', accounts[3]); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const token = yield ctx.deploy({ src: './build/zxc-mock.json', contract: 'Zxc', }); ctx.set('token', token); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const token = ctx.get('token'); const burner = yield ctx.deploy({ src: './build/zxc-burner.json', contract: 'ZxcBurner', args: [token.receipt._address], }); ctx.set('burner', burner); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const BN = ctx.web3.utils.BN; ctx.set('decimalsMul', new BN('1000000000000000000')); ctx.set('totalSupply', new BN('500000000000000000000000000')); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const owner = ctx.get('owner'); const bob = ctx.get('bob'); const jane = ctx.get('jane'); const burner = ctx.get('burner'); const token = ctx.get('token'); yield token.instance.methods.enableTransfer().send({ from: owner }); yield token.instance.methods.transferOwnership(burner.receipt._address).send({ from: owner }); const decimalsMul = ctx.get('decimalsMul'); const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); yield token.instance.methods.transfer(bob, tokenAmount.toString()).send({ from: owner }); yield token.instance.methods.transfer(jane, tokenAmount.toString()).send({ from: owner }); })); spec.test('correctly burns tokens', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const token = ctx.get('token'); const jane = ctx.get('jane'); const owner = ctx.get('owner'); const burner = ctx.get('burner'); const decimalsMul = ctx.get('decimalsMul'); const supply = ctx.get('totalSupply'); const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); yield burner.instance.methods.claim().send({ from: owner }); yield token.instance.methods.approve(burner.receipt._address, tokenAmount.toString()).send({ from: jane }); yield burner.instance.methods.burn(tokenAmount.toString()).send({ from: jane }); const janeBalance = yield token.instance.methods.balanceOf(jane).call(); ctx.is(janeBalance, '0'); const totalSupply = yield token.instance.methods.totalSupply().call(); ctx.is(totalSupply, (supply.sub(tokenAmount)).toString()); })); spec.test('fails burning if ownership not claimed', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const jane = ctx.get('jane'); const token = ctx.get('token'); const burner = ctx.get('burner'); const decimalsMul = ctx.get('decimalsMul'); const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); yield token.instance.methods.approve(burner.receipt._address, tokenAmount.toString()).send({ from: jane }); yield ctx.reverts(() => burner.instance.methods.burn(tokenAmount.toString()).send({ from: jane })); })); spec.test('fails burning when tokens are not approved', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const jane = ctx.get('jane'); const owner = ctx.get('owner'); const burner = ctx.get('burner'); const decimalsMul = ctx.get('decimalsMul'); const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); yield burner.instance.methods.claim().send({ from: owner }); yield ctx.reverts(() => burner.instance.methods.burn(tokenAmount.toString()).send({ from: jane })); })); exports.default = spec; //# sourceMappingURL=zxc-burner.test.js.map