-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
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]>
/// 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 { |
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 remove this interface?
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.
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.
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.
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.
|
||
/// 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" |
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 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
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.
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
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.
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
contracts/NonFungibleToken-v2.cdc
Outdated
access(Withdrawable) fun transfer(id: UInt64, receiver: Capability<&{NonFungibleToken.Receiver}>): Bool { | ||
pre { | ||
receiver.check(): "Could not borrow a reference to the NFT receiver" |
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 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
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'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.
|
||
let expectedCollectionLength = 1 | ||
|
||
txExecutor("setup_account_to_receive_royalty.cdc", [admin], [/storage/flowTokenVault], nil, nil) |
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.
Can you add a comment about why we need to execute this transaction here before minting?
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) | ||
} |
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.
Are these basically the same test?
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 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
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.
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)?
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:
master
branchFiles changed
in the Github PR explorer