"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 deployAndGetContract_1 = require("../../../../../utils/solidity/deployAndGetContract");
const Contracts_1 = require("../../../../../Contracts");
const initTestEnvironment_1 = require("../../../../../tests/utils/initTestEnvironment");
const deployMockSystem_1 = require("../../../../../utils/deploy/deployMockSystem");
const randomAddress_1 = require("../../../../../utils/helpers/randomAddress");
const emptyAddress_1 = require("../../../../../utils/constants/emptyAddress");
const orderSignatures_1 = require("../../../../../utils/constants/orderSignatures");
describe('assetBlacklist', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared.user = shared.env.wallet.address;
        shared.opts = { from: shared.user, gas: 8000000 };
        shared.assetArray = [
            `${randomAddress_1.randomAddress()}`,
            `${randomAddress_1.randomAddress()}`,
            `${randomAddress_1.randomAddress()}`,
            `${randomAddress_1.randomAddress()}`,
            `${randomAddress_1.randomAddress()}`,
        ];
    }));
    it('Create blacklist', () => __awaiter(this, void 0, void 0, function* () {
        const blacklist = yield deployAndGetContract_1.deployAndGetContract(shared.env, Contracts_1.Contracts.AssetBlacklist, [
            shared.assetArray,
        ]);
        expect(yield blacklist.methods.getMembers().call()).toEqual(shared.assetArray);
    }));
    it('Add asset to blacklist', () => __awaiter(this, void 0, void 0, function* () {
        const blacklist = yield deployAndGetContract_1.deployAndGetContract(shared.env, Contracts_1.Contracts.AssetBlacklist, [
            shared.assetArray,
        ]);
        const mockAsset = `${randomAddress_1.randomAddress()}`;
        expect(yield blacklist.methods.getMembers().call()).toEqual(shared.assetArray);
        yield expect(blacklist.methods
            .addToBlacklist(shared.assetArray[0])
            .send({ from: shared.user })).rejects.toThrow('Asset already in blacklist');
        expect(yield blacklist.methods.getMembers().call()).toEqual(shared.assetArray);
        yield expect(blacklist.methods.addToBlacklist(mockAsset).send({ from: shared.user })).resolves.not.toThrow();
        expect(yield blacklist.methods.isMember(mockAsset).call()).toBe(true);
    }));
    it('Policy manager with blacklist', () => __awaiter(this, void 0, void 0, function* () {
        const contracts = yield deployMockSystem_1.deployMockSystem(shared.env, {
            policyManagerContract: Contracts_1.Contracts.PolicyManager,
        });
        const blacklist = yield deployAndGetContract_1.deployAndGetContract(shared.env, Contracts_1.Contracts.AssetBlacklist, [
            shared.assetArray,
        ]);
        const mockAsset = `${randomAddress_1.randomAddress()}`;
        yield contracts.policyManager.methods
            .register(orderSignatures_1.makeOrderSignatureBytes, blacklist.options.address)
            .send({ from: shared.user });
        const validateArgs = [
            orderSignatures_1.makeOrderSignatureBytes,
            [emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, mockAsset, emptyAddress_1.emptyAddress],
            [0, 0, 0],
            '0x0',
        ];
        yield expect(contracts.policyManager.methods.preValidate(...validateArgs).call()).resolves.not.toThrow();
        yield blacklist.methods
            .addToBlacklist(mockAsset)
            .send({ from: shared.user });
        expect(yield blacklist.methods.isMember(mockAsset).call()).toBe(true);
        yield expect(contracts.policyManager.methods.preValidate(...validateArgs).call()).rejects.toThrow('Rule evaluated to false');
    }));
});
