UNPKG

@0xcert/ethereum-value-ledger

Version:

Value ledger module for currency management on the Ethereum blockchain.

69 lines 3.31 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 ethereum_generic_provider_1 = require("@0xcert/ethereum-generic-provider"); const ethereum_sandbox_1 = require("@0xcert/ethereum-sandbox"); const spec_1 = require("@specron/spec"); const ledger_1 = require("../../../core/ledger"); const spec = new spec_1.Spec(); spec.before((stage) => __awaiter(void 0, void 0, void 0, function* () { const protocol = new ethereum_sandbox_1.Protocol(stage.web3); stage.set('protocol', yield protocol.deploy()); })); spec.before((stage) => __awaiter(void 0, void 0, void 0, function* () { const accounts = yield stage.web3.eth.getAccounts(); stage.set('coinbase', accounts[0]); stage.set('bob', accounts[1]); stage.set('sara', accounts[2]); })); spec.test('transfers value to another account', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const coinbase = ctx.get('coinbase'); const bob = ctx.get('bob'); const token = ctx.get('protocol').erc20; const amount = '5000000'; const provider = new ethereum_generic_provider_1.GenericProvider({ client: ctx.web3, accountId: coinbase, requiredConfirmations: 0, }); const ledger = new ledger_1.ValueLedger(provider, ctx.get('protocol').erc20.instance.options.address); const mutation = yield ledger.transferValue({ receiverId: bob, value: amount, }); yield mutation.complete(); ctx.is(mutation.logs[0].event, 'Transfer'); ctx.is(yield token.instance.methods.balanceOf(bob).call(), amount); })); spec.test('transfers approved amount to another account', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const coinbase = ctx.get('coinbase'); const bob = ctx.get('bob'); const sara = ctx.get('sara'); const token = ctx.get('protocol').erc20; const approveAmount = '5000000'; const provider = new ethereum_generic_provider_1.GenericProvider({ client: ctx.web3, accountId: bob, requiredConfirmations: 0, }); const ledger = new ledger_1.ValueLedger(provider, ctx.get('protocol').erc20.instance.options.address); yield token.instance.methods.approve(bob, approveAmount).send({ from: coinbase }); const mutation = yield ledger.transferValue({ senderId: coinbase, receiverId: sara, value: approveAmount, }); yield mutation.complete(); ctx.is(mutation.logs[0].event, 'Transfer'); ctx.is(yield token.instance.methods.balanceOf(sara).call(), approveAmount); })); exports.default = spec; //# sourceMappingURL=transfer-value-method.test.js.map