UNPKG

@0xcert/ethereum-gateway-contracts

Version:

Smart contracts used by the gateway on the Ethereum blockchain.

157 lines 7.53 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 types_2 = require("@0xcert/ethereum-xcert-contracts/src/core/types"); const spec_1 = require("@specron/spec"); const types_3 = require("../../../core/types"); const common = require("../../helpers/common"); const signature_1 = require("../../helpers/signature"); 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('jane', accounts[2]); ctx.set('sara', accounts[3]); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { ctx.set('id1', '1'); ctx.set('imprint1', '0x1e205550c221490347e5e2393a02e94d284bbe9903f023ba098355b8d75974c8'); ctx.set('imprint2', '0x5e20552dc271490347e5e2391b02e94d684bbe9903f023fa098355bed7597434'); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const bob = ctx.get('bob'); const owner = ctx.get('owner'); const imprint1 = ctx.get('imprint1'); const id = ctx.get('id1'); const cat = yield ctx.deploy({ src: '@0xcert/ethereum-xcert-contracts/build/xcert-mock.json', contract: 'XcertMock', args: ['cat', 'CAT', 'https://0xcert.org/', '.json', '0xa65de9e6', ['0x0d04c3b8']], }); yield cat.instance.methods .create(bob, id, imprint1) .send({ from: owner, }); ctx.set('cat', cat); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const updateProxy = yield ctx.deploy({ src: '@0xcert/ethereum-proxy-contracts/build/xcert-update-proxy.json', contract: 'XcertUpdateProxy', }); ctx.set('updateProxy', updateProxy); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const updateProxy = ctx.get('updateProxy'); const owner = ctx.get('owner'); const actionsGateway = yield ctx.deploy({ src: './build/actions-gateway.json', contract: 'ActionsGateway', }); yield actionsGateway.instance.methods.grantAbilities(owner, types_3.ActionsGatewayAbilities.SET_PROXIES).send(); yield actionsGateway.instance.methods.addProxy(updateProxy.receipt._address, 2).send({ from: owner }); ctx.set('actionsGateway', actionsGateway); })); spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { const updateProxy = ctx.get('updateProxy'); const actionsGateway = ctx.get('actionsGateway'); const owner = ctx.get('owner'); yield updateProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, types_1.XcertUpdateProxyAbilities.EXECUTE).send({ from: owner }); })); spec.test('throws when signer does not have ability to sign an update asset', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const actionsGateway = ctx.get('actionsGateway'); const jane = ctx.get('jane'); const bob = ctx.get('bob'); const owner = ctx.get('owner'); const cat = ctx.get('cat'); const id = ctx.get('id1'); const imprint2 = ctx.get('imprint2'); const updateProxy = ctx.get('updateProxy'); const actions = [ { proxyId: 0, contractAddress: cat.receipt._address, params: `${imprint2}${id.substring(2)}00`, }, ]; const orderData = { signers: [jane], actions, seed: common.getCurrentTime(), expirationTimestamp: common.getCurrentTime() + 3600, }; const createTuple = ctx.tuple(orderData); const claim = yield actionsGateway.instance.methods.getOrderDataClaim(createTuple).call(); const signature = yield signature_1.getSignature(ctx.web3, claim, jane); const signatureDataTuple = ctx.tuple([signature]); yield cat.instance.methods.grantAbilities(updateProxy.receipt._address, types_2.XcertAbilities.UPDATE_ASSET_IMPRINT).send({ from: owner }); yield ctx.reverts(() => actionsGateway.instance.methods.perform(createTuple, signatureDataTuple).send({ from: bob }), '015010'); })); spec.test('throws when proxy does not have ability to update assets', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const actionsGateway = ctx.get('actionsGateway'); const jane = ctx.get('jane'); const owner = ctx.get('owner'); const cat = ctx.get('cat'); const id = ctx.get('id1'); const imprint2 = ctx.get('imprint2'); const actions = [ { proxyId: 0, contractAddress: cat.receipt._address, params: `${imprint2}${id.substring(2)}00`, }, ]; const orderData = { signers: [owner], actions, seed: common.getCurrentTime(), expirationTimestamp: common.getCurrentTime() + 3600, }; const createTuple = ctx.tuple(orderData); const claim = yield actionsGateway.instance.methods.getOrderDataClaim(createTuple).call(); const signature = yield signature_1.getSignature(ctx.web3, claim, owner); const signatureDataTuple = ctx.tuple([signature]); yield ctx.reverts(() => actionsGateway.instance.methods.perform(createTuple, signatureDataTuple).send({ from: jane }), '017001'); })); spec.test('throws when proxy does not have ability to execute', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const actionsGateway = ctx.get('actionsGateway'); const updateProxy = ctx.get('updateProxy'); const jane = ctx.get('jane'); const owner = ctx.get('owner'); const cat = ctx.get('cat'); const id = ctx.get('id1'); const imprint2 = ctx.get('imprint2'); const actions = [ { proxyId: 0, contractAddress: cat.receipt._address, params: `${imprint2}${id.substring(2)}00`, }, ]; const orderData = { signers: [owner], actions, seed: common.getCurrentTime(), expirationTimestamp: common.getCurrentTime() + 3600, }; const createTuple = ctx.tuple(orderData); const claim = yield actionsGateway.instance.methods.getOrderDataClaim(createTuple).call(); const signature = yield signature_1.getSignature(ctx.web3, claim, owner); const signatureDataTuple = ctx.tuple([signature]); yield cat.instance.methods.grantAbilities(updateProxy.receipt._address, types_2.XcertAbilities.UPDATE_ASSET_IMPRINT).send({ from: owner }); yield updateProxy.instance.methods.revokeAbilities(actionsGateway.receipt._address, types_1.XcertUpdateProxyAbilities.EXECUTE).send({ from: owner }); yield ctx.reverts(() => actionsGateway.instance.methods.perform(createTuple, signatureDataTuple).send({ from: jane }), '017001'); })); exports.default = spec; //# sourceMappingURL=update-fail.test.js.map