-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor!: add methods() to contract abigen #592
Conversation
While I was updating the harness tests I figured that I could also update some test that I did not update when I made the let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT));
let mut wallets = launch_custom_provider_and_get_wallets(config, None).await;
let wallet = wallets.pop().unwrap();
let wallet_2 = wallets.pop().unwrap();
setup_contract_test!(
contract_instance,
None,
"packages/fuels/tests/test_projects/contract_test"
); Let me know what you think about this 😄 |
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! 👍
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.
Love it.
self | ||
} | ||
|
||
pub fn wallet(&mut self, wallet: WalletUnlocked) -> &mut Self { |
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.
Why do we need this and with_wallet
? I understand that with_wallet
returns a new instance, but having them both is confusing. We should at least rename them, although I am more for deleting one unless there is an explicit need for it.
let provider = self.wallet.get_provider()?; | ||
wallet.set_provider(provider.clone()); | ||
|
||
Ok(Self { contract_id: self.contract_id.clone(), wallet: wallet }) | ||
} | ||
|
||
pub fn methods(&self) -> #methods_name { | ||
#methods_name { contract_id: self.contract_id.clone(), wallet: self.wallet.clone() } |
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.
Should this have a reference to the instance instead? What should the user expect to happen if they change the wallet of the instance with the above wallet()
method.
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.
They must call methods()
again. AFAIK rust will not allow to have a reference to a dropped wallet. As the new one would replace it.
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 creates a pitfall. It's not evident that if you change the wallet, the methods are affected too.
Can we use a reference to the actual instance or add a warning to the docs?
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 am writing this without trying it out). wallet()
and with_wallet
both create a new instance so I think the reference is again a no go. IMO documentation should be enough.
wallet()
does not create a new instance. We have two options:
- Try to have a reference inside methods to the instance. (I do not know if this will make problems when wallet moves)
- Remove
wallet()
andcontract_id()
(you can always make a new instance)
I am leaning toward the second option. If you use with_wallet
you create a new instance and have to call methods
again..
For context, I copied the wallet()
and contract_id()
methods from the old builder.
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 implemented the second option.
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.
Super clean implementation; goodbye name conflicts! 🎉
closes: #515
Builder
pattern from abigencontract instance
Now the workflow looks like this:
In the tests where we have multiple contract calls, I have saved the methods in a new variable and called the methods directly. For example: