UNPKG

@0xcert/ethereum-gateway-contracts

Version:

Smart contracts used by the gateway on the Ethereum blockchain.

78 lines 4.27 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 types_1 = require("../../../core/types"); 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('zeroAddress', '0x0000000000000000000000000000000000000000'); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const tokenProxy = yield ctx.deploy({ src: '@0xcert/ethereum-proxy-contracts/build/token-transfer-proxy.json', contract: 'TokenTransferProxy', }); ctx.set('tokenProxy', tokenProxy); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const nftProxy = yield ctx.deploy({ src: '@0xcert/ethereum-proxy-contracts/build/nftoken-transfer-proxy.json', contract: 'NFTokenTransferProxy', }); ctx.set('nftProxy', nftProxy); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const owner = ctx.get('owner'); const actionsGateway = yield ctx.deploy({ src: './build/actions-gateway.json', contract: 'ActionsGateway', }); yield actionsGateway.instance.methods.grantAbilities(owner, types_1.ActionsGatewayAbilities.SET_PROXIES).send(); ctx.set('actionsGateway', actionsGateway); })); spec.test('correctly adds proxy addresses', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const tokenProxy = ctx.get('tokenProxy'); const nftProxy = ctx.get('nftProxy'); const owner = ctx.get('owner'); const actionsGateway = ctx.get('actionsGateway'); const logs = yield actionsGateway.instance.methods.addProxy(tokenProxy.receipt._address, 0).send({ from: owner }); ctx.not(logs.events.ProxyChange, undefined); let proxy = yield actionsGateway.instance.methods.proxies(0).call(); ctx.is(tokenProxy.receipt._address, proxy.proxyAddress); yield actionsGateway.instance.methods.addProxy(nftProxy.receipt._address, 0).send({ from: owner }); proxy = yield actionsGateway.instance.methods.proxies(1).call(); ctx.is(nftProxy.receipt._address, proxy.proxyAddress); })); spec.test('correctly removes proxy address', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const tokenProxy = ctx.get('tokenProxy'); const zeroAddress = ctx.get('zeroAddress'); const owner = ctx.get('owner'); const actionsGateway = ctx.get('actionsGateway'); const addLogs = yield actionsGateway.instance.methods.addProxy(tokenProxy.receipt._address, 1).send({ from: owner }); ctx.not(addLogs.events.ProxyChange, undefined); let proxy = yield actionsGateway.instance.methods.proxies(0).call(); ctx.is(tokenProxy.receipt._address, proxy.proxyAddress); const removeLogs = yield actionsGateway.instance.methods.removeProxy(0).send({ from: owner }); ctx.not(removeLogs.events.ProxyChange, undefined); proxy = yield actionsGateway.instance.methods.proxies(0).call(); ctx.is(zeroAddress, proxy.proxyAddress); })); spec.test('throws when a third party tries to add proxy address', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const zeroAddress = ctx.get('zeroAddress'); const bob = ctx.get('bob'); const actionsGateway = ctx.get('actionsGateway'); yield ctx.reverts(() => actionsGateway.instance.methods.addProxy(zeroAddress, 0).send({ from: bob })); })); exports.default = spec; //# sourceMappingURL=proxies.test.js.map