"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const token_math_1 = require("@melonproject/token-math");
const initTestEnvironment_1 = require("../../../../tests/utils/initTestEnvironment");
const getToken_1 = require("../calls/getToken");
const transfer_1 = require("../transactions/transfer");
const onTransfer_1 = require("../events/onTransfer");
const deploy_1 = require("../transactions/deploy");
describe('onTransfer', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared.address = yield deploy_1.deployToken(shared.env);
        shared.token = yield getToken_1.getToken(shared.env, shared.address);
        shared.accounts = (yield shared.env.eth.getAccounts()).map(account => new token_math_1.Address(account));
    }));
    it('onTransfer', (done) => __awaiter(this, void 0, void 0, function* () {
        onTransfer_1.onTransfer(shared.env, shared.token.address, {
            from: new token_math_1.Address(shared.accounts[0]),
        }).subscribe(a => {
            expect(a.from).toBe(shared.accounts[0].toString());
            expect(a.to).toBe(shared.accounts[1].toString());
            expect(a.value).toBe('1000000000000000000');
            done();
        });
        yield transfer_1.transfer(shared.env, {
            howMuch: token_math_1.createQuantity(shared.token, '1000000000000000000'),
            to: shared.accounts[1],
        });
    }));
});
