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

feat: dryRun and simulate will add output variables #549

Merged
merged 5 commits into from
Nov 1, 2022
Merged

Conversation

QuinnLee
Copy link
Contributor

@QuinnLee QuinnLee commented Oct 27, 2022

TLDR

using dryRun or simulate will add output variables.

@QuinnLee QuinnLee self-assigned this Oct 27, 2022
@QuinnLee QuinnLee force-pushed the ql/530 branch 3 times, most recently from 419b9b7 to 73b9f12 Compare October 27, 2022 03:32
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 2022

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
90.15% (+0.01% 🔼)
3579/3970
🟡 Branches
72.75% (+0.17% 🔼)
702/965
🟢 Functions
88.03% (+0.04% 🔼)
721/819
🟢 Lines
90.16% (+0% 🔼)
3428/3802
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / base-locked-wallet.ts
90.91% (-0.95% 🔻)
70% 93.33%
90.91% (-0.95% 🔻)

Test suite run success

542 tests passing in 49 suites.

Report generated by 🧪jest coverage report action from 0559a93

@QuinnLee QuinnLee requested review from luizstacio, LuizAsFight, camsjams and a team October 27, 2022 12:29
@@ -53,4 +53,50 @@ describe('TokenTestContract', () => {
const tokenBalance = balances.find((b) => b.assetId === token.id.toB256());
expect(tokenBalance?.amount.toHex()).toEqual(toHex(50));
});

it('Can add variable estimations', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('Can add variable estimations', async () => {
it('Automatically add variableOuputs', async () => {

@@ -184,6 +195,29 @@ export class BaseInvocationScope<TReturn = any> {
return this;
}

async addMissingVariableOutputs(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think missing variables should happen in the same place we estimate gasFee for transactions on the provider level.

const { gasUsed, minGasPrice } = await this.getTransactionCost(transactionRequest, 0);

And it should happen on dryRun and sendTransaction also. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this.

For clarification:
dryRun on the base-invocation-scope uses provider.call, I can add it to both provider.sendTransaction and provider.call functions.

Copy link
Member

@luizstacio luizstacio Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the issue I just thought about on the send transaction is that doing on the provider, will not be possible to change the tx, but we could return errors as we do with gas. And maybe an instruction on how to get this info first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct, signTransaction and populateTransactionWitnessesSignature are on the wallet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luizstacio - I refactored provider.call to add the variables. But I'm having issues with provider.sendTransaction. The gas estimation + adding output variables results in test failures. My suggestion is to merge the new provider.call code in this PR and open another issue to add feature to provider.sendTransaction so this PR doesn't get too old and we can ship smaller chunks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea on sendTransaction is to run the check for variable outputs on dry run mode with UTXO Validation false. If it doesn't have variable outputs just throw an error. If tests fail would be because of missing variable outputs. Otherwise, it should keep passing no?

camsjams
camsjams previously approved these changes Oct 27, 2022
Copy link
Contributor

@camsjams camsjams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good pending other changes

@@ -235,12 +245,17 @@ export default class Provider {
* Submits a transaction to the chain to be executed
*/
async sendTransaction(
transactionRequestLike: TransactionRequestLike
transactionRequestLike: TransactionRequestLike,
{ signTransaction }: Partial<ProviderCallParams> = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some thoughts on this;

  1. The signing process should take place before the tx arrives at the provider level.
  2. getReceiptsWithMissingOutputVariables should always run on dryRun mode with utxValidation: off, avoiding signing a tx on its try. Also, imagining a scenario where the user needs to approve every try would make the UX bad.

@QuinnLee QuinnLee force-pushed the ql/530 branch 4 times, most recently from 3345613 to b6f7b29 Compare October 31, 2022 16:18
@QuinnLee QuinnLee requested review from camsjams, luizstacio and a team October 31, 2022 18:39
@QuinnLee QuinnLee enabled auto-merge (squash) October 31, 2022 21:20
camsjams
camsjams previously approved these changes Oct 31, 2022
@QuinnLee QuinnLee requested review from digorithm, camsjams and a team November 1, 2022 03:43
Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- LGTM!

@QuinnLee QuinnLee merged commit db8cc6b into master Nov 1, 2022
@QuinnLee QuinnLee deleted the ql/530 branch November 1, 2022 13:23
@QuinnLee QuinnLee linked an issue Nov 2, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add variables outputs automatically by simulating tx
4 participants