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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 42 additions & 25 deletions packages/tasit-action/src/contract/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,71 @@ import ConfigLoader from "../ConfigLoader";
export class Action extends Subscription {
#provider;
#signer;
#rawTx;
#rawAction;
#tx;
#txConfirmations = 0;
#timeout;
#lastConfirmationTime;
#isRunning = false;

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;
};

#fillRawAction = async rawTx => {
const nonce = await this.#provider.getTransactionCount(
this.#signer.address
);

const network = await this.#provider.getNetwork();
const { chainId } = network;

let { value } = rawTx;
value = !value ? 0 : value;

// Note: Gas estimation should be improved
// See: https://github.com/tasitlabs/TasitSDK/issues/173
//
// This command isn't working
const gasPrice = 1e9;

rawTx = { ...rawTx, nonce, chainId, value, gasPrice };

// Note: Gas estimation should be improved
// See: https://github.com/tasitlabs/TasitSDK/issues/173
//
// This command isn't working
//const gasLimit = await this.#provider.estimateGas(rawTx);
const gasLimit = 7e6;

rawTx = { ...rawTx, gasLimit };

return rawTx;
};

#signAndSend = async () => {
try {
// 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,
};

const nonce = await this.#provider.getTransactionCount(
this.#signer.address
);

let rawTx = await this.#rawTx;

rawTx = { ...rawTx, nonce, ...gasParams };

const signedTx = await this.#signer.sign(rawTx);
// Note: Resolving promise if the Action was created using a async rawTx
const rawAction = await this.#rawAction;

this.#rawAction = await this.#fillRawAction(rawAction);

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

this.#tx = await this.#provider.sendTransaction(signedTx);
} catch (error) {
Expand Down
7 changes: 5 additions & 2 deletions packages/tasit-action/src/contract/Contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,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 @@ -516,7 +518,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 Down
5 changes: 4 additions & 1 deletion packages/tasit-action/src/erc721/ERC721Full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ describe("TasitAction.ERC721.ERC721Full", () => {
await expectExactTokenBalances(erc721, [ana.address], [1]);
});

it("should transfer an owned token", async () => {
// Non-deterministic
// Enable again after solve this isse:
// https://github.com/tasitlabs/TasitSDK/issues/367
it.skip("should transfer an owned token", async () => {
erc721 = new ERC721Full(ERC721_FULL_ADDRESS, ana);

const transferListener = sinon.fake(message => {
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;
};
}