@0xcert/ethereum-gateway-contracts
Version:
Smart contracts used by the gateway on the Ethereum blockchain.
157 lines • 6.6 kB
JavaScript
"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 common = require("../helpers/common");
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('owner', accounts[0]);
ctx.set('jane', accounts[1]);
ctx.set('sara', accounts[2]);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const jane = ctx.get('jane');
const zxc = yield ctx.deploy({
src: '@0xcert/ethereum-erc20-contracts/build/token-mock.json',
contract: 'TokenMock',
args: ['ERC20', 'ERC', 18, '300000000000000000000000000'],
from: jane,
});
ctx.set('zxc', zxc);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenDeployProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/token-deploy-proxy.json',
contract: 'TokenDeployProxy',
});
ctx.set('tokenDeployProxy', tokenDeployProxy);
}));
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 tokenDeployProxy = ctx.get('tokenDeployProxy');
const tokenProxy = ctx.get('tokenProxy');
const tokenDeployGateway = yield ctx.deploy({
src: './build/token-deploy-gateway.json',
contract: 'TokenDeployGateway',
args: [
tokenDeployProxy.receipt._address,
tokenProxy.receipt._address,
],
});
ctx.set('tokenDeployGateway', tokenDeployGateway);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenProxy = ctx.get('tokenProxy');
const tokenDeployGateway = ctx.get('tokenDeployGateway');
const owner = ctx.get('owner');
yield tokenProxy.instance.methods.grantAbilities(tokenDeployGateway.receipt._address, types_1.TokenTransferProxyAbilities.EXECUTE).send({ from: owner });
}));
spec.test('cancels an deploy', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenDeployGateway = ctx.get('tokenDeployGateway');
const zxc = ctx.get('zxc');
const jane = ctx.get('jane');
const owner = ctx.get('owner');
const deployData = {
maker: jane,
taker: owner,
deployData: {
name: 'test',
symbol: 'TST',
supply: '5000000000000000000000000',
decimals: '18',
owner: jane,
},
paymentData: {
token: zxc.receipt._address,
to: owner,
value: '10000',
},
seed: common.getCurrentTime(),
expirationTimestamp: common.getCurrentTime() + 3600,
};
const createTuple = ctx.tuple(deployData);
const logs = yield tokenDeployGateway.instance.methods.cancel(createTuple).send({ from: jane });
ctx.not(logs.events.Cancel, undefined);
}));
spec.test('fails when not the maker tries to cancel deploy', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenDeployGateway = ctx.get('tokenDeployGateway');
const zxc = ctx.get('zxc');
const jane = ctx.get('jane');
const owner = ctx.get('owner');
const deployData = {
maker: jane,
taker: owner,
deployData: {
name: 'test',
symbol: 'TST',
supply: '5000000000000000000000000',
decimals: '18',
owner: jane,
},
paymentData: {
token: zxc.receipt._address,
to: owner,
value: '10000',
},
seed: common.getCurrentTime(),
expirationTimestamp: common.getCurrentTime() + 3600,
};
const createTuple = ctx.tuple(deployData);
yield ctx.reverts(() => tokenDeployGateway.instance.methods.cancel(createTuple).send({ from: owner }), '011007');
}));
spec.test('fails when trying to cancel an alredy performed deploy', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenDeployGateway = ctx.get('tokenDeployGateway');
const zxc = ctx.get('zxc');
const tokenProxy = ctx.get('tokenProxy');
const jane = ctx.get('jane');
const owner = ctx.get('owner');
const deployData = {
maker: jane,
taker: owner,
deployData: {
name: 'test',
symbol: 'TST',
supply: '5000000000000000000000000',
decimals: '18',
owner: jane,
},
paymentData: {
token: zxc.receipt._address,
to: owner,
value: '10000',
},
seed: common.getCurrentTime(),
expirationTimestamp: common.getCurrentTime() + 3600,
};
const createTuple = ctx.tuple(deployData);
const claim = yield tokenDeployGateway.instance.methods.getDeployDataClaim(createTuple).call();
const signature = yield ctx.web3.eth.sign(claim, jane);
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`) + 27,
kind: 0,
};
const signatureDataTuple = ctx.tuple(signatureData);
yield zxc.instance.methods.approve(tokenProxy.receipt._address, 10000).send({ from: jane });
yield tokenDeployGateway.instance.methods.perform(createTuple, signatureDataTuple).send({ from: owner });
yield ctx.reverts(() => tokenDeployGateway.instance.methods.cancel(createTuple).send({ from: jane }), '011006');
}));
exports.default = spec;
//# sourceMappingURL=cancel-instance-method.test.js.map