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 5 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.

56 changes: 34 additions & 22 deletions packages/tasit-action/src/contract/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,43 @@ export class Action extends Subscription {
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 {
// 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 gasPrice = await this.#provider.getGasPrice();
const network = await this.#provider.getNetwork();
const chainId = network.chainId;
let { value } = rawTx;
value = !value ? 0 : value;

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

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

this.#rawAction = { ...rawTx, gasLimit };
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

Expand Down
28 changes: 28 additions & 0 deletions packages/tasit-action/src/contract/Contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,37 @@ describe("TasitAction.Contract", () => {

await mineBlocks(provider, 2);

// Non-determinitic
expect(confirmationListener.callCount).to.be.at.least(1);
expect(errorListener.called).to.be.false;
});

it("'once' listener should be unsubscribed only after user listener function was called", async () => {
action = sampleContract.setValue(rand);

const errorListener = sinon.fake(error => {
console.log(error);
action.off("error");
});

const confirmationListener = sinon.fake(message => {
console.log(message);
});

action.on("error", errorListener);
action.once("confirmation", confirmationListener);

// Forcing internal (block) listener to be called before the transaction is sent
await mineBlocks(provider, 2);

await action.send();
await action.waitForOneConfirmation();

await mineBlocks(provider, 2);

expect(confirmationListener.called).to.be.true;
expect(errorListener.called).to.be.false;
});
});

describe("Contract Events Subscription", async () => {
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-determinitic
pcowgill marked this conversation as resolved.
Show resolved Hide resolved
// 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