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

Standard v2 Cadence 1.0 updates #194

Merged
merged 31 commits into from
Nov 7, 2023
Merged

Conversation

sisyphusSmiling
Copy link
Collaborator

@sisyphusSmiling sisyphusSmiling commented Oct 20, 2023

Related: #133

Description

This PR updates the repo's Cadence contracts, transactions and scripts as well as supporting test suites for Cadence 1.0 compatibility. As such, it targets the standard-v2 branch where work on v2 of NonFungibleToken is ongoing.

All go tests are passing, but a bug in test account address retrieval prevents a couple of the Cadence test cases from passing.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels
  • Update the version in package.json when there is a change in the smart contracts

dependabot bot and others added 24 commits September 6, 2023 16:56
Bumps [github.com/ethereum/go-ethereum](https://github.com/ethereum/go-ethereum) from 1.9.13 to 1.12.1.
- [Release notes](https://github.com/ethereum/go-ethereum/releases)
- [Commits](ethereum/go-ethereum@v1.9.13...v1.12.1)

---
updated-dependencies:
- dependency-name: github.com/ethereum/go-ethereum
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.10.0 to 0.17.0.
- [Commits](golang/net@v0.10.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
@sisyphusSmiling sisyphusSmiling added Improvement SC-Eng Issues that we want to see surfaced in SC-Eng ZH Board labels Oct 24, 2023
@sisyphusSmiling sisyphusSmiling changed the title [WIP] Standard v2 Cadence 1.0 updates Standard v2 Cadence 1.0 updates Oct 31, 2023
@sisyphusSmiling sisyphusSmiling marked this pull request as ready for review October 31, 2023 21:08
@sisyphusSmiling sisyphusSmiling self-assigned this Oct 31, 2023
/// This interface is now a general purpose metadata interface because
/// a public interface is needed to get metadata, but adding a whole new interface
/// for every account to upgrade to is probably too much of a breaking change
access(all) resource interface Balance { //: ViewResolver.Resolver {
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching that. I didn't mean to remove the interface. I see it's in the current v2 implementation, so not sure how that got removed. I'll make sure to re-include it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Revisiting this, looks like there is not a Balance interface defined in FT-v2. I think I assumed that it was omitted on purpose, but worth revisiting if not.

contracts/ExampleNFT-v2.cdc Show resolved Hide resolved

/// Function for a direct transfer instead of having to do a deposit and withdrawal
/// This can and should return false if the transfer doesn't succeed and true if it does succeed
///
access(Withdrawable) fun transfer(id: UInt64, receiver: Capability<&{NonFungibleToken.Receiver}>): Bool {
pre {
receiver.check(): "Could not borrow a reference to the NFT receiver"
//NonFungibleToken.emitNFTTransfer(id: id, uuid: self.borrowNFTSafe(id: id)?.uuid, from: self.owner?.address, to: receiver.borrow()?.owner?.address, type: self.borrowNFT(id).getType().identifier)
self.getIDs().contains(id): "The collection does not contain the specified ID"
Copy link
Member

Choose a reason for hiding this comment

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

This could be a problem because some collections are so large that they can't return the whole list of IDs because it goes over the gas limit. might need to remove this. lets try to get some other opinions though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. FWIW I think it's best to remove it to keep the interface flexible, but worth bringing up in the open house this week

Copy link
Collaborator Author

@sisyphusSmiling sisyphusSmiling Nov 7, 2023

Choose a reason for hiding this comment

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

If we want to proceed here, the problem then is in the NonFungibleToken.emitNFTTransfer(..., type: self.borrowNFT(id).getType().identifier). We'll need to determine if we can emit String? otherwise the self.getIDs().contains(id) pre-condition remains necessary. FWIW I'll add the condition back in and leave it as a point of discussion

Comment on lines 276 to 278
access(Withdrawable) fun transfer(id: UInt64, receiver: Capability<&{NonFungibleToken.Receiver}>): Bool {
pre {
receiver.check(): "Could not borrow a reference to the NFT receiver"
Copy link
Member

Choose a reason for hiding this comment

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

I made the return type of this a Bool because I thought it might be nice to let people return false if something went wrong instead of reverting. What do you think about removing all the pre-conditions here to help support that? I guess that would make it so we can't emit the transfer event every time though because it might fail. Not sure what is better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a good question. My stance is we remove the pre-condition and proceed with your original idea. That said, I think this is a good question to present at the open house this week and see what others think. For the purpose of this PR, I say we leave it as-is until we get more feedback about it.

scripts/get_collection_length.cdc Outdated Show resolved Hide resolved
scripts/get_collection_length_from_storage.cdc Outdated Show resolved Hide resolved

let expectedCollectionLength = 1

txExecutor("setup_account_to_receive_royalty.cdc", [admin], [/storage/flowTokenVault], nil, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment about why we need to execute this transaction here before minting?

Comment on lines +138 to +156
access(all) fun testGetCollectionIDs() {
let expectedCollectionLength = 1

let actualNFTIDs = scriptExecutor("get_collection_ids.cdc", [
recipient.address,
/public/cadenceExampleNFTCollection
]) as! [UInt64]? ?? panic("Could not get collection IDs")

Test.assertEqual(expectedCollectionLength, actualNFTIDs.length)
}

access(all) fun testGetCollectionLength() {
let expectedCollectionLength = 1

let actualCollectionLength = scriptExecutor("get_collection_length.cdc", [admin.address]) as! Int?
?? panic("Could not get collection length")

Test.assertEqual(expectedCollectionLength, actualCollectionLength)
}
Copy link
Member

Choose a reason for hiding this comment

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

Are these basically the same test?

Copy link
Member

Choose a reason for hiding this comment

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

I know we're using different scripts, but we should probably be making sure the IDs are correct in the first one instead of just checking the length

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These could probably be consolidated into one test, but they do use different scripts since one now uses .getIDs() and the other uses .getLength().

Not sure how we would validate the id given it's the uuid. Maybe confirming NFT.uuid == NFT.getID() && collection.getIDs().contains(id)?

tests/test_helpers.cdc Outdated Show resolved Hide resolved
@sisyphusSmiling sisyphusSmiling merged commit 683df24 into standard-v2 Nov 7, 2023
0 of 2 checks passed
@sisyphusSmiling sisyphusSmiling deleted the standard-v2-updates branch November 7, 2023 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement SC-Eng Issues that we want to see surfaced in SC-Eng ZH Board
Projects
Development

Successfully merging this pull request may close these issues.

2 participants