@0xcert/ethereum-gateway-contracts
Version:
Smart contracts used by the gateway on the Ethereum blockchain.
101 lines • 4.42 kB
JavaScript
;
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 spec_1 = require("@specron/spec");
const common = require("../../helpers/common");
const spec = new spec_1.Spec();
exports.default = 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* () {
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,
});
ctx.set('cat', cat);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = yield ctx.deploy({
src: './build/actions-gateway.json',
contract: 'ActionsGateway',
});
ctx.set('actionsGateway', actionsGateway);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const action = {
proxyId: 0,
contractAddress: ctx.get('cat').receipt._address,
params: `${ctx.get('jane')}${ctx.get('sara').substr(2)}`,
};
const claim = {
signers: [ctx.get('jane'), ctx.get('sara')],
actions: [action],
seed: common.getCurrentTime(),
expiration: common.getCurrentTime() + 600,
};
const actionsGateway = ctx.get('actionsGateway');
const tuple = ctx.tuple(claim);
const hash = yield actionsGateway.instance.methods.getOrderDataClaim(tuple).call();
ctx.set('hash', hash);
}));
spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () {
const hash = ctx.get('hash');
const account = ctx.get('jane');
const signature = yield ctx.web3.eth.sign(hash, account);
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`) + 27,
kind: 0,
};
ctx.set('signature', signatureData);
}));
spec.test('check valid signature', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const account = ctx.get('jane');
const hash = ctx.get('hash');
const signature = ctx.get('signature');
const tuple = ctx.tuple(signature);
const valid = yield actionsGateway.instance.methods.isValidSignature(account, hash, tuple).call();
ctx.true(valid);
}));
spec.test('check invalid signature', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const signatureData = ctx.get('signature');
signatureData.v = 30;
const account = ctx.get('jane');
const hash = ctx.get('hash');
const tuple = ctx.tuple(signatureData);
const valid = yield actionsGateway.instance.methods.isValidSignature(account, hash, tuple).call();
ctx.false(valid);
}));
spec.test('check signature from a third party account', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const actionsGateway = ctx.get('actionsGateway');
const account = ctx.get('sara');
const hash = ctx.get('hash');
const signature = ctx.get('signature');
const tuple = ctx.tuple(signature);
const valid = yield actionsGateway.instance.methods.isValidSignature(account, hash, tuple).call();
ctx.false(valid);
}));
//# sourceMappingURL=claims.test.js.map