@0xcert/ethereum-gateway-contracts
Version:
Smart contracts used by the gateway on the Ethereum blockchain.
207 lines • 8.91 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 deployProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/xcert-deploy-proxy.json',
contract: 'XcertDeployProxy',
});
ctx.set('deployProxy', deployProxy);
}));
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 createProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/xcert-create-proxy.json',
contract: 'XcertCreateProxy',
});
ctx.set('createProxy', createProxy);
}));
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 manageProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/abilitable-manage-proxy.json',
contract: 'AbilitableManageProxy',
});
ctx.set('manageProxy', manageProxy);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const nftTransferProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/nftoken-safe-transfer-proxy.json',
contract: 'NFTokenSafeTransferProxy',
});
ctx.set('nftTransferProxy', nftTransferProxy);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const burnProxy = yield ctx.deploy({
src: '@0xcert/ethereum-proxy-contracts/build/xcert-burn-proxy.json',
contract: 'XcertBurnProxy',
});
ctx.set('burnProxy', burnProxy);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const deployProxy = ctx.get('deployProxy');
const tokenProxy = ctx.get('tokenProxy');
const createProxy = ctx.get('createProxy');
const updateProxy = ctx.get('updateProxy');
const manageProxy = ctx.get('manageProxy');
const nftTransferProxy = ctx.get('nftTransferProxy');
const burnProxy = ctx.get('burnProxy');
const xcertDeployGateway = yield ctx.deploy({
src: './build/xcert-deploy-gateway.json',
contract: 'XcertDeployGateway',
args: [
deployProxy.receipt._address,
tokenProxy.receipt._address,
createProxy.receipt._address,
updateProxy.receipt._address,
manageProxy.receipt._address,
nftTransferProxy.receipt._address,
burnProxy.receipt._address,
],
});
ctx.set('xcertDeployGateway', xcertDeployGateway);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const tokenProxy = ctx.get('tokenProxy');
const xcertDeployGateway = ctx.get('xcertDeployGateway');
const owner = ctx.get('owner');
yield tokenProxy.instance.methods.grantAbilities(xcertDeployGateway.receipt._address, types_1.TokenTransferProxyAbilities.EXECUTE).send({ from: owner });
}));
spec.test('cancels an deploy', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const xcertDeployGateway = ctx.get('xcertDeployGateway');
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',
uriPrefix: 'https://base.com/',
uriPostfix: '.json',
schemaId: '0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658',
capabilities: ['0x9d118770', '0x0d04c3b8', '0xbedb86fb', '0x20c5429b'],
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 xcertDeployGateway.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 xcertDeployGateway = ctx.get('xcertDeployGateway');
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',
uriPrefix: 'https://base.com/',
uriPostfix: '.json',
schemaId: '0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658',
capabilities: ['0x9d118770', '0x0d04c3b8', '0xbedb86fb', '0x20c5429b'],
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(() => xcertDeployGateway.instance.methods.cancel(createTuple).send({ from: owner }), '009007');
}));
spec.test('fails when trying to cancel an alredy performed deploy', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const xcertDeployGateway = ctx.get('xcertDeployGateway');
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',
uriPrefix: 'https://base.com/',
uriPostfix: '.json',
schemaId: '0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658',
capabilities: ['0x9d118770', '0x0d04c3b8', '0xbedb86fb', '0x20c5429b'],
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 xcertDeployGateway.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 xcertDeployGateway.instance.methods.perform(createTuple, signatureDataTuple).send({ from: owner });
}));
exports.default = spec;
//# sourceMappingURL=cancel-instance-method.test.js.map