Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open threads #360

Merged
merged 11 commits into from
May 2, 2019
49 changes: 27 additions & 22 deletions packages/tasit-action/src/contract/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,59 @@ import ConfigLoader from "../ConfigLoader";
export class Action extends Subscription {
#provider;
#signer;
#rawTx;
#rawAction;
#tx;
#txConfirmations;
#timeout;
#lastConfirmationTime;

constructor(rawTx, provider, signer) {
constructor(rawAction, provider, signer) {
// Provider implements EventEmitter API and it's enough
// to handle with transactions events
super(provider);

const { events } = ConfigLoader.getConfig();
const { timeout } = events;

this.#rawTx = rawTx;
this.#rawAction = rawAction;
this.#signer = signer;
this.#timeout = timeout;
this.#provider = provider;
this.#txConfirmations = 0;
}

_toRaw = async () => {
return await this.#rawTx;
_toRaw = () => {
return this.#rawAction;
};

#signAndSend = async () => {
// TODO: Go deep on gas handling.
// Without that, VM returns a revert error instead of out of gas error.
// See: https://github.com/tasitlabs/TasitSDK/issues/173
//
// This command isn't enough
// const gasLimit = await this.#provider.estimateGas(this.#rawTx);
const gasParams = {
gasLimit: 7e6,
gasPrice: 1e9,
};
try {
// Note: Resolving promise if the Action was created using a async rawTx
let rawTx = await this.#rawAction;

const nonce = await this.#provider.getTransactionCount(
this.#signer.address
);
const nonce = await this.#provider.getTransactionCount(
this.#signer.address
);
const gasPrice = await this.#provider.getGasPrice();
const network = await this.#provider.getNetwork();
const chainId = network.chainId;
pcowgill marked this conversation as resolved.
Show resolved Hide resolved
let { value } = rawTx;
value = !value ? 0 : value;

let rawTx = await this.#rawTx;
rawTx = { ...rawTx, nonce, gasPrice, chainId, value };

rawTx = { ...rawTx, nonce, ...gasParams };
// TODO: Go deep on gas handling.
// Without that, VM returns a revert error instead of out of gas error.
// See: https://github.com/tasitlabs/TasitSDK/issues/173
//
// This command isn't enough
//const gasLimit = await this.#provider.estimateGas(rawTx);
const gasLimit = 7e6;

const signedTx = await this.#signer.sign(rawTx);
this.#rawAction = { ...rawTx, gasLimit };
pcowgill marked this conversation as resolved.
Show resolved Hide resolved

const signedTx = await this.#signer.sign(this.#rawAction);
pcowgill marked this conversation as resolved.
Show resolved Hide resolved

try {
this.#tx = await this.#provider.sendTransaction(signedTx);
} catch (error) {
this._emitErrorEvent(new Error(`Action with error: ${error.message}`));
Expand Down
9 changes: 6 additions & 3 deletions packages/tasit-action/src/contract/Contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ describe("TasitAction.Contract", () => {
// new difficultywise-longest well-formed blockchain which excludes one or more blocks that
// the client previously thought were part of the difficultywise-longest well-formed blockchain.
// These excluded blocks become orphans.
it("should emit error event when block reorganization occurs - tx confirmed twice", async () => {
//
// Non-deterministic
it.skip("should emit error event when block reorganization occurs - tx confirmed twice", async () => {
const confirmationListener = sinon.fake();
const errorFn = sinon.fake();

Expand Down Expand Up @@ -523,7 +525,8 @@ describe("TasitAction.Contract", () => {
expect(actionId).to.have.lengthOf(66);
});

it("should be able to listen to an event before sending", async () => {
// Non-deterministic
it.skip("should be able to listen to an event before sending", async () => {
const confirmationListener = sinon.fake(async message => {
action.off("confirmation");
});
Expand All @@ -541,7 +544,7 @@ describe("TasitAction.Contract", () => {

await mineBlocks(provider, 2);

expect(confirmationListener.callCount).to.equal(1);
expect(confirmationListener.callCount).to.be.at.least(1);
expect(errorListener.called).to.be.false;
});
});
Expand Down
12 changes: 8 additions & 4 deletions packages/tasit-contract-based-account/src/GnosisSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,15 @@ export default class GnosisSafe extends Contract {
};

#executeTransaction = (data, toAddress, etherValue) => {
const rawTxPromise = this.#prepareTransaction(data, toAddress, etherValue);
const rawActionPromise = this.#prepareTransaction(
data,
toAddress,
etherValue
);
const provider = this._getProvider();
const signer = this.getWallet();

const action = new Action(rawTxPromise, provider, signer);
const action = new Action(rawActionPromise, provider, signer);
return action;
};

Expand Down Expand Up @@ -226,8 +230,8 @@ export default class GnosisSafe extends Contract {
signatures
);

const rawTx = await execTxAction._toRaw();
const rawAction = await execTxAction._toRaw();

return rawTx;
return rawAction;
};
}