-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
419b9b7
to
73b9f12
Compare
Coverage report
Show files with reduced coverage 🔻
Test suite run success542 tests passing in 49 suites. Report generated by 🧪jest coverage report action from 0559a93 |
@@ -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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('Can add variable estimations', async () => { | |
it('Automatically add variableOuputs', async () => { |
packages/contract/src/contracts/functions/base-invocation-scope.ts
Outdated
Show resolved
Hide resolved
packages/contract/src/contracts/functions/base-invocation-scope.ts
Outdated
Show resolved
Hide resolved
@@ -184,6 +195,29 @@ export class BaseInvocationScope<TReturn = any> { | |||
return this; | |||
} | |||
|
|||
async addMissingVariableOutputs( |
There was a problem hiding this comment.
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.
fuels-ts/packages/providers/src/provider.ts
Line 242 in 2cf77e8
const { gasUsed, minGasPrice } = await this.getTransactionCost(transactionRequest, 0); |
And it should happen on dryRun
and sendTransaction
also. What do you think?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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
packages/providers/src/provider.ts
Outdated
@@ -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> = {} |
There was a problem hiding this comment.
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;
- The signing process should take place before the tx arrives at the provider level.
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.
3345613
to
b6f7b29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice -- LGTM!
TLDR
using
dryRun
orsimulate
will add output variables.