UNPKG

@0xcert/ethereum-gateway-contracts

Version:

Smart contracts used by the gateway on the Ethereum blockchain.

136 lines 6.3 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 types_1 = require("@0xcert/ethereum-proxy-contracts/src/core/types"); const spec_1 = require("@specron/spec"); const types_2 = require("../../../core/types"); const common = require("../../helpers/common"); const signature_1 = require("../../helpers/signature"); const spec = new spec_1.Spec(); spec.before((ctx) => __awaiter(void 0, void 0, void 0, function* () { const accounts = yield ctx.web3.eth.getAccounts(); ctx.set('id1', '0x0000000000000000000000000000000000000000000000000000000000000001'); 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 cat = yield ctx.deploy({ src: '@0xcert/ethereum-erc721-contracts/build/nf-token-metadata-enumerable-mock.json', contract: 'NFTokenMetadataEnumerableMock', args: ['cat', 'CAT', 'https://0xcert.org/', '.json'], }); yield cat.instance.methods .create(ctx.get('jane'), 1) .send({ from: ctx.get('owner'), gas: 4000000, }); yield cat.instance.methods .create(ctx.get('jane'), 4) .send({ from: ctx.get('owner'), gas: 4000000, }); yield cat.instance.methods .create(ctx.get('bob'), 2) .send({ from: ctx.get('owner'), gas: 4000000, }); yield cat.instance.methods .create(ctx.get('bob'), 3) .send({ from: ctx.get('owner'), gas: 4000000, }); ctx.set('cat', cat); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const nftSafeProxy = yield ctx.deploy({ src: '@0xcert/ethereum-proxy-contracts/build/nftoken-safe-transfer-proxy.json', contract: 'NFTokenSafeTransferProxy', }); ctx.set('nftSafeProxy', nftSafeProxy); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const nftSafeProxy = ctx.get('nftSafeProxy'); const owner = ctx.get('owner'); const actionsGateway = yield ctx.deploy({ src: './build/actions-gateway.json', contract: 'ActionsGateway', }); yield actionsGateway.instance.methods.grantAbilities(owner, types_2.ActionsGatewayAbilities.SET_PROXIES).send(); yield actionsGateway.instance.methods.addProxy(nftSafeProxy.receipt._address, 1).send({ from: owner }); ctx.set('actionsGateway', actionsGateway); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const nftSafeProxy = ctx.get('nftSafeProxy'); const actionsGateway = ctx.get('actionsGateway'); const owner = ctx.get('owner'); yield nftSafeProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, types_1.NFTokenSafeTransferProxyAbilities.EXECUTE).send({ from: owner }); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const actionsGateway = ctx.get('actionsGateway'); const nftSafeProxy = ctx.get('nftSafeProxy'); const jane = ctx.get('jane'); const bob = ctx.get('bob'); const cat = ctx.get('cat'); const id1 = ctx.get('id1'); const actions = [ { proxyId: 0, contractAddress: cat.receipt._address, params: `${id1}${bob.substring(2)}00`, }, ]; const orderData = { signers: [jane], actions, seed: common.getCurrentTime(), expiration: common.getCurrentTime() + 600, }; const orderDataTuple = ctx.tuple(orderData); const claim = yield actionsGateway.instance.methods.getOrderDataClaim(orderDataTuple).call(); const signature = yield signature_1.getSignature(ctx.web3, claim, jane); const signatureDataTuple = ctx.tuple([signature]); yield cat.instance.methods.approve(nftSafeProxy.receipt._address, 1).send({ from: jane }); ctx.set('signatureTuple', signatureDataTuple); ctx.set('dataTuple', orderDataTuple); })); spec.test('succeeds', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const signatureTuple = ctx.get('signatureTuple'); const dataTuple = ctx.get('dataTuple'); const actionsGateway = ctx.get('actionsGateway'); const jane = ctx.get('jane'); const bob = ctx.get('bob'); const logs = yield actionsGateway.instance.methods.cancel(dataTuple).send({ from: jane }); ctx.not(logs.events.Cancel, undefined); yield ctx.reverts(() => actionsGateway.instance.methods.perform(dataTuple, signatureTuple).send({ from: bob }), '015006'); })); spec.test('throws when trying to cancel an already performed atomic swap', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const signatureTuple = ctx.get('signatureTuple'); const dataTuple = ctx.get('dataTuple'); const actionsGateway = ctx.get('actionsGateway'); const jane = ctx.get('jane'); const bob = ctx.get('bob'); yield actionsGateway.instance.methods.perform(dataTuple, signatureTuple).send({ from: bob }); yield ctx.reverts(() => actionsGateway.instance.methods.cancel(dataTuple).send({ from: jane }), '015007'); })); spec.test('throws when a third party tries to cancel an atomic swap', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const dataTuple = ctx.get('dataTuple'); const actionsGateway = ctx.get('actionsGateway'); const sara = ctx.get('sara'); yield ctx.reverts(() => actionsGateway.instance.methods.cancel(dataTuple).send({ from: sara }), '015008'); })); exports.default = spec; //# sourceMappingURL=cancel.test.js.map