New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@0xcert/ethereum-generic-provider

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xcert/ethereum-generic-provider - npm Package Compare versions

Comparing version 0.0.0-alpha6 to 0.0.0-alpha7

6

dist/core/errors.js

@@ -21,3 +21,3 @@ "use strict";

|| stringError.indexOf('006002') > 0
|| stringError.indexOf('010001') > 0) {
|| stringError.indexOf('007003') > 0) {
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_NFT, error);

@@ -33,3 +33,3 @@ }

|| stringError.indexOf('006004') > 0
|| stringError.indexOf('008001') > 0
|| stringError.indexOf('007004') > 0
|| stringError.indexOf('017001') > 0

@@ -56,3 +56,3 @@ || stringError.indexOf('018001') > 0

}
else if (stringError.indexOf('009001') > 0) {
else if (stringError.indexOf('007002') > 0) {
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.TRANSFERS_PAUSED, error);

@@ -59,0 +59,0 @@ }

@@ -36,3 +36,3 @@ /// <reference types="node" />

off(event: MutationEvent, handler?: () => any): this;
resolve(): Promise<{}>;
resolve(): Promise<this>;
forget(): this;

@@ -39,0 +39,0 @@ protected loopUntilResolved(): Promise<any>;

@@ -76,9 +76,9 @@ "use strict";

}
return new Promise((resolve, reject) => {
yield new Promise((resolve, reject) => {
if (!this.isResolved()) {
this.once(types_1.MutationEvent.RESOLVE, () => resolve(this));
this.once(types_1.MutationEvent.RESOLVE, () => resolve());
this.once(types_1.MutationEvent.ERROR, (err) => reject(err));
}
else {
resolve(this);
resolve();
}

@@ -89,2 +89,3 @@ if (start) {

});
return this;
});

@@ -104,3 +105,3 @@ }

}
else if (!tx.to) {
else if (!tx.to || tx.to === '0x0') {
tx.to = yield this.getTransactionReceipt().then((r) => r.contractAddress);

@@ -111,3 +112,3 @@ }

this.$confirmations = yield this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber || lastBlock));
if (this.confirmations >= 25) {
if (this.$confirmations >= this.$provider.requiredConfirmations) {
this.$status = MutationStatus.RESOLVED;

@@ -114,0 +115,0 @@ this.emit(types_1.MutationEvent.RESOLVE, this);

@@ -7,2 +7,5 @@ import { RpcResponse, SendOptions, SignMethod } from './types';

unsafeRecipientIds?: string[];
assetLedgerSource?: string;
valueLedgerSource?: string;
requiredConfirmations?: number;
}

@@ -13,2 +16,5 @@ export declare class GenericProvider {

unsafeRecipientIds: string[];
assetLedgerSource: string;
valueLedgerSource: string;
requiredConfirmations: number;
protected $client: any;

@@ -18,3 +24,4 @@ protected $id: number;

post(options: SendOptions): Promise<RpcResponse>;
protected request(options: SendOptions): Promise<RpcResponse>;
protected getNextId(): number;
}

@@ -17,4 +17,7 @@ "use strict";

this.accountId = options.accountId;
this.signMethod = options.signMethod || types_1.SignMethod.ETH_SIGN;
this.unsafeRecipientIds = options.unsafeRecipientIds || [];
this.assetLedgerSource = options.assetLedgerSource || 'https://cdn.jsdelivr.net/gh/xpepermint/0xcert-contracts/asset-ledger.json',
this.valueLedgerSource = options.valueLedgerSource || 'https://cdn.jsdelivr.net/gh/xpepermint/0xcert-contracts/value-ledger.json',
this.signMethod = typeof options.signMethod !== 'undefined' ? options.signMethod : types_1.SignMethod.ETH_SIGN;
this.requiredConfirmations = typeof options.requiredConfirmations !== 'undefined' ? options.requiredConfirmations : 1;
this.$client = options.client && options.client.currentProvider

@@ -26,47 +29,21 @@ ? options.client.currentProvider

return __awaiter(this, void 0, void 0, function* () {
if (options.method === 'eth_sendTransaction' && options.params.length > 0) {
if (typeof options.params[0].gas === 'undefined') {
options.method = 'eth_estimateGas';
const res = yield new Promise((resolve, reject) => {
this.$client.send(Object.assign({ jsonrpc: '2.0', id: this.getNextId() }, options), (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw errors_1.parseError(err);
});
options.params[0].gas = Math.ceil(res.result * 1.1).toString(16);
options.method = 'eth_sendTransaction';
const payload = Object.assign({}, options);
if (payload.method === 'eth_sendTransaction' && payload.params.length) {
if (typeof payload.params[0].gas === 'undefined') {
const res = yield this.request(Object.assign({}, payload, { method: 'eth_estimateGas' }));
payload.params[0].gas = Math.ceil(res.result * 1.1).toString(16);
}
if (typeof options.params[0].gasPrice === 'undefined') {
const res = yield new Promise((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: this.getNextId(),
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw errors_1.parseError(err);
});
const multiplyer = 1.1;
options.params[0].gasPrice = Math.ceil(res.result * multiplyer).toString(16);
if (typeof payload.params[0].gasPrice === 'undefined') {
const res = yield this.request(Object.assign({}, payload, { method: 'eth_gasPrice', params: [] }));
payload.params[0].gasPrice = Math.ceil(res.result * 1.1).toString(16);
}
}
const requestIndex = options.id || this.getNextId();
return this.request(payload);
});
}
request(options) {
return __awaiter(this, void 0, void 0, function* () {
const payload = Object.assign({ jsonrpc: '2.0', id: options.id || this.getNextId() }, options);
return new Promise((resolve, reject) => {
this.$client.send(Object.assign({ jsonrpc: '2.0', id: requestIndex }, options), (err, res) => {
this.$client.send(payload, (err, res) => {
if (err) {

@@ -78,3 +55,3 @@ return reject(err);

}
else if (res.id !== requestIndex) {
else if (res.id !== payload.id) {
return reject('Invalid RPC id');

@@ -81,0 +58,0 @@ }

@@ -39,3 +39,3 @@ "use strict";

}));
spec.test('correctly throws ZERO_ADDRESS error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws ZERO_ADDRESS error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721 = ctx.get('protocol').erc721;

@@ -61,3 +61,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

}));
spec.test('correctly throws INVALID_NFT error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws INVALID_NFT error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721 = ctx.get('protocol').erc721;

@@ -90,3 +90,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

}));
spec.test('correctly throws NOT_AUTHORIZED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws NOT_AUTHORIZED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721 = ctx.get('protocol').erc721;

@@ -141,3 +141,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

}));
spec.test('correctly throws RECEIVER_DOES_NOT_SUPPORT_NFT error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws RECEIVER_DOES_NOT_SUPPORT_NFT error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721 = ctx.get('protocol').erc721;

@@ -163,3 +163,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

}));
spec.test('correctly throws NFT_ALREADY_EXISTS error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws NFT_ALREADY_EXISTS error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721 = ctx.get('protocol').erc721;

@@ -186,3 +186,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

}));
spec.test('correctly throws INVALID_INDEX error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws INVALID_INDEX error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const erc721Enumerable = ctx.get('protocol').erc721Enumerable;

@@ -201,3 +201,3 @@ const owner = ctx.get('owner');

}));
spec.test('correctly throws TRANSFERS_PAUSED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws TRANSFERS_PAUSED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const pausableXcert = ctx.get('protocol').xcertPausable;

@@ -213,3 +213,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws INVALID_SIGNATURE_KIND error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws INVALID_SIGNATURE_KIND error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -230,3 +230,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws INVALID_PROXY error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws INVALID_PROXY error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -270,3 +270,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws YOU_ARE_NOT_THE_TAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws YOU_ARE_NOT_THE_TAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -312,3 +312,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws SENDER_NOT_TAKER_OR_MAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws SENDER_NOT_TAKER_OR_MAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -353,3 +353,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws ORDER_EXPIRED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws ORDER_EXPIRED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -394,3 +394,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws INVALID_SIGNATURE error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws INVALID_SIGNATURE error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -437,3 +437,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws ORDER_CANCELED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws ORDER_CANCELED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -479,3 +479,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws ORDER_CANNOT_BE_PERFORMED_TWICE error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws ORDER_CANNOT_BE_PERFORMED_TWICE error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -521,3 +521,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws YOU_ARE_NOT_THE_MAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws YOU_ARE_NOT_THE_MAKER error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -551,3 +551,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws SIGNER_NOT_AUTHORIZED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws SIGNER_NOT_AUTHORIZED error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -590,3 +590,3 @@ const jane = ctx.get('jane');

}));
spec.test('correctly throws ONE_ZERO_ABILITY_HAS_TO_EXIST error', (ctx) => __awaiter(this, void 0, void 0, function* () {
spec.test('throws ONE_ZERO_ABILITY_HAS_TO_EXIST error', (ctx) => __awaiter(this, void 0, void 0, function* () {
const owner = ctx.get('owner');

@@ -593,0 +593,0 @@ const xcert = ctx.get('protocol').xcert;

@@ -27,2 +27,3 @@ "use strict";

client: stage.web3,
requiredConfirmations: 1,
});

@@ -36,7 +37,3 @@ stage.set('provider', provider);

const counters = { confirm: 0, resolve: 0 };
const { transactionHash } = yield ctx.web3.eth.sendTransaction({
from: coinbase,
to: bob,
value: 100000,
});
const transactionHash = yield ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 }).then((t) => t.transactionHash);
const mutation = new __1.Mutation(provider, transactionHash);

@@ -46,13 +43,14 @@ mutation.on(__1.MutationEvent.CONFIRM, () => counters.confirm++);

mutation.resolve();
yield ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 });
ctx.true(mutation.isPending());
yield mutation.resolve();
ctx.true(mutation.isResolved());
ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
ctx.is(counters.confirm, 1);
ctx.is(counters.resolve, 1);
ctx.is(mutation.confirmations, 1);
ctx.is(mutation.id, transactionHash);
ctx.is(mutation.senderId, coinbase.toLowerCase());
ctx.is(mutation.receiverId, bob.toLowerCase());
ctx.is(counters.confirm, 1);
}));
exports.default = spec;
//# sourceMappingURL=resolve-instance-method.test.js.map
{
"files": {
"packages/0xcert-ethereum-generic-provider/nodemon.json": "82b893373db9861f1df4b55d8ea68a5d37b118de",
"packages/0xcert-ethereum-generic-provider/package.json": "45bf3c66d9d5b3b0290b15d29d7c2e400763ce09",
"packages/0xcert-ethereum-generic-provider/src/core/errors.ts": "4a3e19bb1a68371e5adfdfd4b1d42098ff73d17c",
"packages/0xcert-ethereum-generic-provider/src/core/mutation.ts": "31cd40c11d4f23d9a4ce8d664ddf8ad752bb6355",
"packages/0xcert-ethereum-generic-provider/src/core/provider.ts": "ac15e5ffa9b6623667443d54d6944c2a55865545",
"packages/0xcert-ethereum-generic-provider/package.json": "b5b7d0b22086b1551dab9380047425c3294dad85",
"packages/0xcert-ethereum-generic-provider/src/core/errors.ts": "f38b9faa1a8e686733600b8bf24c7dd42d292a76",
"packages/0xcert-ethereum-generic-provider/src/core/mutation.ts": "02368c2a5292972e09a21bf074b5e6ba6ebeba2e",
"packages/0xcert-ethereum-generic-provider/src/core/provider.ts": "8884fe350e5d30dc7173879943d7f5e086c88619",
"packages/0xcert-ethereum-generic-provider/src/core/types.ts": "02bd82e1d363f2c4e0e11ac1317a6f548d84220c",
"packages/0xcert-ethereum-generic-provider/src/index.ts": "a4b6262ea7cb45960084814850cb98a8717b05e8",
"packages/0xcert-ethereum-generic-provider/src/tests/core/errors/errors.test.ts": "43c3d85967dd885274306679ef78af32c94ef851",
"packages/0xcert-ethereum-generic-provider/src/tests/core/mutation/resolve-instance-method.test.ts": "e39edc93c56ac25d19418af0ab082b5052307ac8",
"packages/0xcert-ethereum-generic-provider/src/tests/core/errors/errors.test.ts": "a41844229d5c6026e07873ab12e4d929dbbc4e0c",
"packages/0xcert-ethereum-generic-provider/src/tests/core/mutation/resolve-instance-method.test.ts": "8b2f87d47792434dd8677ae700c6112425aa9afe",
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/send-instance-method.test.ts": "083c4d7c89ba9bbe89bd3ddff62f10a27b932502",
"packages/0xcert-ethereum-generic-provider/src/tests/index.test.ts": "8f3b7d1d01c857ac2d3231518a012242fc0607a5",
"packages/0xcert-ethereum-generic-provider/tsconfig.json": "4aeac3c20e45b7e477e82012eb7788f7dbb11bf3",
"common/config/rush/npm-shrinkwrap.json": "4bd0ff28a23360cdc0ee7546713b1819a52577cd"
"common/config/rush/npm-shrinkwrap.json": "b5af47441ed8345fd5cfe61bc37d9d7008283a33"
},
"arguments": "npx specron test "
"arguments": "npm run clean; npx tsc "
}
{
"name": "@0xcert/ethereum-generic-provider",
"version": "0.0.0-alpha6",
"version": "0.0.0-alpha7",
"description": "Ethereum ledger for 0xcert protocol.",

@@ -15,3 +15,2 @@ "main": "./dist/index.js",

"port": 8520,
"blockTime": 0.1,
"match": [

@@ -27,3 +26,3 @@ "./src/tests/**/*.test.ts"

"devDependencies": {
"@0xcert/ethereum-sandbox": "0.0.0-alpha6",
"@0xcert/ethereum-sandbox": "0.0.0-alpha7",
"@types/node": "^10.12.10",

@@ -38,5 +37,5 @@ "@specron/cli": "^0.5.0",

"dependencies": {
"@0xcert/ethereum-utils": "0.0.0-alpha6",
"@0xcert/scaffold": "0.0.0-alpha6"
"@0xcert/ethereum-utils": "0.0.0-alpha7",
"@0xcert/scaffold": "0.0.0-alpha7"
}
}

@@ -27,3 +27,3 @@ import { ProviderError, ProviderIssue } from '@0xcert/scaffold';

|| stringError.indexOf('006002') > 0
|| stringError.indexOf('010001') > 0) {
|| stringError.indexOf('007003') > 0) {
return new ProviderError(ProviderIssue.INVALID_NFT, error);

@@ -39,3 +39,3 @@ }

|| stringError.indexOf('006004') > 0
|| stringError.indexOf('008001') > 0
|| stringError.indexOf('007004') > 0
|| stringError.indexOf('017001') > 0

@@ -62,3 +62,3 @@ || stringError.indexOf('018001') > 0

}
else if (stringError.indexOf('009001') > 0) {
else if (stringError.indexOf('007002') > 0) {
return new ProviderError(ProviderIssue.TRANSFERS_PAUSED, error);

@@ -65,0 +65,0 @@ }

@@ -141,11 +141,10 @@ import { EventEmitter } from 'events';

return new Promise((resolve, reject) => {
await new Promise((resolve, reject) => {
if (!this.isResolved()) {
this.once(MutationEvent.RESOLVE, () => resolve(this));
this.once(MutationEvent.RESOLVE, () => resolve());
this.once(MutationEvent.ERROR, (err) => reject(err));
}
else {
resolve(this);
resolve();
}
if (start) {

@@ -155,2 +154,4 @@ this.loopUntilResolved();

});
return this;
}

@@ -177,3 +178,3 @@

}
else if (!tx.to) {
else if (!tx.to || tx.to === '0x0') {
tx.to = await this.getTransactionReceipt().then((r) => r.contractAddress);

@@ -186,3 +187,3 @@ }

if (this.confirmations >= 25) {
if (this.$confirmations >= this.$provider.requiredConfirmations) {
this.$status = MutationStatus.RESOLVED;

@@ -189,0 +190,0 @@ this.emit(MutationEvent.RESOLVE, this);

@@ -5,3 +5,3 @@ import { RpcResponse, SendOptions, SignMethod } from './types';

/**
*
* Configuration interface for generic provider.
*/

@@ -13,2 +13,5 @@ export interface GenericProviderOptions {

unsafeRecipientIds?: string[];
assetLedgerSource?: string;
valueLedgerSource?: string;
requiredConfirmations?: number;
}

@@ -23,2 +26,5 @@

public unsafeRecipientIds: string[];
public assetLedgerSource: string;
public valueLedgerSource: string;
public requiredConfirmations: number;
protected $client: any;

@@ -34,5 +40,8 @@ protected $id: number = 0;

this.accountId = options.accountId;
this.signMethod = options.signMethod || SignMethod.ETH_SIGN;
this.unsafeRecipientIds = options.unsafeRecipientIds || [];
this.assetLedgerSource = options.assetLedgerSource || 'https://cdn.jsdelivr.net/gh/xpepermint/0xcert-contracts/asset-ledger.json',
this.valueLedgerSource = options.valueLedgerSource || 'https://cdn.jsdelivr.net/gh/xpepermint/0xcert-contracts/value-ledger.json',
this.signMethod = typeof options.signMethod !== 'undefined' ? options.signMethod : SignMethod.ETH_SIGN;
this.requiredConfirmations = typeof options.requiredConfirmations !== 'undefined' ? options.requiredConfirmations : 1;
this.$client = options.client && options.client.currentProvider

@@ -44,3 +53,3 @@ ? options.client.currentProvider

/**
* Sends a raw RPC request through the provider.
* Sends a raw request to the JSON RPC serveer.
* @param options.method RPC procedure name.

@@ -53,68 +62,48 @@ * @param options.params RPC procedure parameters.

public async post(options: SendOptions): Promise<RpcResponse> {
// TODO: testi if this works if error throwing works on ropsten or do we need to check if the
// resulting gas amount is the same as block gas amount => revert.
// if making a transaction where gas is not defined we calculate it using estimateGas.
if (options.method === 'eth_sendTransaction' && options.params.length > 0) {
if (typeof options.params[0].gas === 'undefined') {
options.method = 'eth_estimateGas';
const res = await new Promise<RpcResponse>((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
id: this.getNextId(),
...options,
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw parseError(err);
const payload = { ...options };
// TODO: test if error throwing works on ropsten or do we need to check if
// the resulting gas amount is the same as block gas amount => revert.
if (payload.method === 'eth_sendTransaction' && payload.params.length) {
if (typeof payload.params[0].gas === 'undefined') {
const res = await this.request({
...payload,
method: 'eth_estimateGas',
});
// estimate gas is sometimes in accurate (depends on the node). So to be sure we have enough
// gas we multiply result with 1.2.
//options.params[0].gas = res.result;
options.params[0].gas = Math.ceil(res.result * 1.1).toString(16);
options.method = 'eth_sendTransaction';
// estimate gas is sometimes inaccurate (depends on the node). So to be
// sure we have enough gas, we multiply result with a factor.
payload.params[0].gas = Math.ceil(res.result * 1.1).toString(16);
}
if (typeof options.params[0].gasPrice === 'undefined') {
// get gas price
const res = await new Promise<RpcResponse>((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: this.getNextId(),
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw parseError(err);
if (typeof payload.params[0].gasPrice === 'undefined') {
const res = await this.request({
...payload,
method: 'eth_gasPrice',
params: [],
});
// TODO: get multiplyer from provider settings
const multiplyer = 1.1;
options.params[0].gasPrice = Math.ceil(res.result * multiplyer).toString(16);
payload.params[0].gasPrice = Math.ceil(res.result * 1.1).toString(16);
}
}
const requestIndex = options.id || this.getNextId();
return this.request(payload);
}
/**
* Sends a raw request to the JSON RPC serveer.
* @param options.method RPC procedure name.
* @param options.params RPC procedure parameters.
* @param options.id RPC request identifier.
* @param options.jsonrpc RPC protocol version.
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC
*/
protected async request(options: SendOptions) {
const payload = {
jsonrpc: '2.0',
id: options.id || this.getNextId(),
...options,
};
return new Promise<RpcResponse>((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
id: requestIndex,
...options,
}, (err, res) => {
this.$client.send(payload, (err, res) => {
if (err) { // client error

@@ -126,3 +115,3 @@ return reject(err);

}
else if (res.id !== requestIndex) { // anomaly
else if (res.id !== payload.id) { // anomaly
return reject('Invalid RPC id');

@@ -138,3 +127,3 @@ }

/**
* Returns the next unique instance `requestIndex`.
* Returns the next unique request number.
*/

@@ -141,0 +130,0 @@ protected getNextId() {

@@ -42,3 +42,3 @@ import { Spec } from '@specron/spec';

spec.test('correctly throws ZERO_ADDRESS error', async (ctx) => {
spec.test('throws ZERO_ADDRESS error', async (ctx) => {
const erc721 = ctx.get('protocol').erc721;

@@ -65,3 +65,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

spec.test('correctly throws INVALID_NFT error', async (ctx) => {
spec.test('throws INVALID_NFT error', async (ctx) => {
const erc721 = ctx.get('protocol').erc721;

@@ -95,3 +95,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

spec.test('correctly throws NOT_AUTHORIZED error', async (ctx) => {
spec.test('throws NOT_AUTHORIZED error', async (ctx) => {
const erc721 = ctx.get('protocol').erc721;

@@ -149,3 +149,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

// TODO: For some reason the revert happens on another level so is throws a general revert.
spec.test('correctly throws RECEIVER_DOES_NOT_SUPPORT_NFT error', async (ctx) => {
spec.test('throws RECEIVER_DOES_NOT_SUPPORT_NFT error', async (ctx) => {
const erc721 = ctx.get('protocol').erc721;

@@ -173,3 +173,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

spec.test('correctly throws NFT_ALREADY_EXISTS error', async (ctx) => {
spec.test('throws NFT_ALREADY_EXISTS error', async (ctx) => {
const erc721 = ctx.get('protocol').erc721;

@@ -197,3 +197,3 @@ const erc721Metadata = ctx.get('protocol').erc721Metadata;

spec.test('correctly throws INVALID_INDEX error', async (ctx) => {
spec.test('throws INVALID_INDEX error', async (ctx) => {
const erc721Enumerable = ctx.get('protocol').erc721Enumerable;

@@ -213,3 +213,3 @@ const owner = ctx.get('owner');

spec.test('correctly throws TRANSFERS_PAUSED error', async (ctx) => {
spec.test('throws TRANSFERS_PAUSED error', async (ctx) => {
const pausableXcert = ctx.get('protocol').xcertPausable;

@@ -227,3 +227,3 @@ const jane = ctx.get('jane');

// TODO: Because revert is done with revert() not require() ganache does not throw message.
spec.test('correctly throws INVALID_SIGNATURE_KIND error', async (ctx) => {
spec.test('throws INVALID_SIGNATURE_KIND error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -246,3 +246,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws INVALID_PROXY error', async (ctx) => {
spec.test('throws INVALID_PROXY error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -293,3 +293,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws YOU_ARE_NOT_THE_TAKER error', async (ctx) => {
spec.test('throws YOU_ARE_NOT_THE_TAKER error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -341,3 +341,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws SENDER_NOT_TAKER_OR_MAKER error', async (ctx) => {
spec.test('throws SENDER_NOT_TAKER_OR_MAKER error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -388,3 +388,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws ORDER_EXPIRED error', async (ctx) => {
spec.test('throws ORDER_EXPIRED error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -434,3 +434,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws INVALID_SIGNATURE error', async (ctx) => {
spec.test('throws INVALID_SIGNATURE error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -482,3 +482,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws ORDER_CANCELED error', async (ctx) => {
spec.test('throws ORDER_CANCELED error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -528,3 +528,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws ORDER_CANNOT_BE_PERFORMED_TWICE error', async (ctx) => {
spec.test('throws ORDER_CANNOT_BE_PERFORMED_TWICE error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -574,3 +574,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws YOU_ARE_NOT_THE_MAKER error', async (ctx) => {
spec.test('throws YOU_ARE_NOT_THE_MAKER error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -608,3 +608,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws SIGNER_NOT_AUTHORIZED error', async (ctx) => {
spec.test('throws SIGNER_NOT_AUTHORIZED error', async (ctx) => {
const orderGateway = ctx.get('protocol').orderGateway;

@@ -651,3 +651,3 @@ const jane = ctx.get('jane');

spec.test('correctly throws ONE_ZERO_ABILITY_HAS_TO_EXIST error', async (ctx) => {
spec.test('throws ONE_ZERO_ABILITY_HAS_TO_EXIST error', async (ctx) => {
const owner = ctx.get('owner');

@@ -654,0 +654,0 @@ const xcert = ctx.get('protocol').xcert;

@@ -16,3 +16,3 @@ import { Spec } from '@specron/spec';

const protocol = new Protocol(stage.web3);
stage.set('protocol', await protocol.deploy());

@@ -31,2 +31,3 @@ });

client: stage.web3,
requiredConfirmations: 1,
});

@@ -43,8 +44,3 @@

const { transactionHash } = await ctx.web3.eth.sendTransaction({
from: coinbase,
to: bob,
value: 100000,
});
const transactionHash = await ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 }).then((t) => t.transactionHash);
const mutation = new Mutation(provider, transactionHash);

@@ -55,2 +51,3 @@ mutation.on(MutationEvent.CONFIRM, () => counters.confirm++)

mutation.resolve();
await ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 }); // simulate new block
ctx.true(mutation.isPending());

@@ -60,10 +57,10 @@ await mutation.resolve();

ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
ctx.is(counters.confirm, 1);
ctx.is(counters.resolve, 1);
ctx.is(mutation.confirmations, 1);
ctx.is(mutation.id, transactionHash);
ctx.is(mutation.senderId, coinbase.toLowerCase());
ctx.is(mutation.receiverId, bob.toLowerCase());
ctx.is(counters.confirm, 1);
});
export default spec;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc