@0xcert/ethereum-gateway-contracts
Version:
Smart contracts used by the gateway on the Ethereum blockchain.
143 lines • 6.96 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 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('owner', accounts[0]);
ctx.set('bob', accounts[1]);
ctx.set('jane', 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 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 tokenProxy = ctx.get('tokenProxy');
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(tokenProxy.receipt._address, 1).send({ from: owner });
ctx.set('actionsGateway', actionsGateway);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenProxy = ctx.get('tokenProxy');
const actionsGateway = ctx.get('actionsGateway');
const owner = ctx.get('owner');
yield tokenProxy.instance.methods.grantAbilities(actionsGateway.receipt._address, types_1.TokenTransferProxyAbilities.EXECUTE).send({ from: owner });
}));
spec.test('when current time is after expirationTimestamp', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const tokenProxy = ctx.get('tokenProxy');
const jane = ctx.get('jane');
const bob = ctx.get('bob');
const zxc = ctx.get('zxc');
const zxcAmountHex = '0x0000000000000000000000000000000000000000000000000000000000000BB8';
const actions = [
{
proxyId: 0,
contractAddress: zxc.receipt._address,
params: `${zxcAmountHex}${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 zxc.instance.methods.approve(tokenProxy.receipt._address, zxcAmountHex).send({ from: jane });
yield ctx.reverts(() => actionsGateway.instance.methods.perform(orderDataTuple, signatureDataTuple).send({ from: bob }), '015004');
}));
spec.test('when signature is invalid', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const tokenProxy = ctx.get('tokenProxy');
const jane = ctx.get('jane');
const bob = ctx.get('bob');
const zxc = ctx.get('zxc');
const zxcAmountHex = '0x0000000000000000000000000000000000000000000000000000000000000BB8';
const actions = [
{
proxyId: 0,
contractAddress: zxc.receipt._address,
params: `${zxcAmountHex}${bob.substring(2)}00`,
},
];
const orderData = {
signers: [jane],
actions,
seed: common.getCurrentTime(),
expiration: common.getCurrentTime() + 600,
};
let orderDataTuple = ctx.tuple(orderData);
const claim = yield actionsGateway.instance.methods.getOrderDataClaim(orderDataTuple).call();
orderData.actions[0].proxyId = 1;
orderDataTuple = ctx.tuple(orderData);
const signature = yield signature_1.getSignature(ctx.web3, claim, jane);
const signatureDataTuple = ctx.tuple([signature]);
yield zxc.instance.methods.approve(tokenProxy.receipt._address, zxcAmountHex).send({ from: jane });
yield ctx.reverts(() => actionsGateway.instance.methods.perform(orderDataTuple, signatureDataTuple).send({ from: bob }), '015005');
}));
spec.test('trying to perform an alredy pefromed swap', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const tokenProxy = ctx.get('tokenProxy');
const jane = ctx.get('jane');
const bob = ctx.get('bob');
const zxc = ctx.get('zxc');
const zxcAmountHex = '0x0000000000000000000000000000000000000000000000000000000000000BB8';
const actions = [
{
proxyId: 0,
contractAddress: zxc.receipt._address,
params: `${zxcAmountHex}${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 zxc.instance.methods.approve(tokenProxy.receipt._address, zxcAmountHex).send({ from: jane });
yield actionsGateway.instance.methods.perform(orderDataTuple, signatureDataTuple).send({ from: bob });
yield ctx.reverts(() => actionsGateway.instance.methods.perform(orderDataTuple, signatureDataTuple).send({ from: bob }), '015007');
}));
exports.default = spec;
//# sourceMappingURL=fail.test.js.map