Skip to content

Commit

Permalink
update setup transaction to include metadata views (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan authored May 30, 2022
1 parent 2f9399e commit af0924d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions lib/go/test/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func TestMarketDeployment(t *testing.T) {
// Should be able to deploy the MetadataViews contract
// as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, err := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -148,7 +149,8 @@ func TestMarketV1(t *testing.T) {
// Should be able to deploy the MetadataViews contract
// as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, err := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -679,12 +681,13 @@ func TestMarketV3(t *testing.T) {
_, err = b.CommitBlock()
assert.NoError(t, err)

env.NFTAddress = nftAddr.String()
env.NFTAddress = "0x" + nftAddr.String()

// Should be able to deploy the MetadataViews contract
// as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, err := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down
22 changes: 14 additions & 8 deletions lib/go/test/topshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const (
MetadataViewsContractsBaseURL = "https://raw.githubusercontent.com/onflow/flow-nft/master/contracts/"
MetadataViewsInterfaceFile = "MetadataViews.cdc"

emulatorFTAddress = "ee82856bf20e2aa6"
emulatorFlowTokenAddress = "0ae53cb6e3f42a79"
MetadataReplaceAddress = `"./utility/FungibleToken.cdc"`
emulatorFTAddress = "ee82856bf20e2aa6"
emulatorFlowTokenAddress = "0ae53cb6e3f42a79"
MetadataFTReplaceAddress = `"./utility/FungibleToken.cdc"`
MetadataNFTReplaceAddress = `"./NonFungibleToken.cdc"`
)

// This test is for testing the deployment the topshot smart contracts
Expand All @@ -52,7 +53,8 @@ func TestNFTDeployment(t *testing.T) {
// Should be able to deploy the MetadataViews contract
// as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, err := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -134,7 +136,8 @@ func TestMintNFTs(t *testing.T) {

// Should be able to deploy a contract as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, err := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -659,7 +662,8 @@ func TestTransferAdmin(t *testing.T) {

// Should be able to deploy a contract as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, _ := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -761,7 +765,8 @@ func TestSetPlaysOwnedByAddressScript(t *testing.T) {

// Should be able to deploy a contract as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, _ := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down Expand Up @@ -958,7 +963,8 @@ func TestDestroyMoments(t *testing.T) {

// Should be able to deploy a contract as a new account with no keys.
metadataViewsCode, _ := DownloadFile(MetadataViewsContractsBaseURL + MetadataViewsInterfaceFile)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract := strings.Replace(string(metadataViewsCode), MetadataFTReplaceAddress, "0x"+emulatorFTAddress, 1)
parsedMetadataContract = strings.Replace(parsedMetadataContract, MetadataNFTReplaceAddress, "0x"+nftAddr.String(), 1)
metadataViewsAddr, _ := b.CreateAccount(nil, []sdktemplates.Contract{
{
Name: "MetadataViews",
Expand Down
4 changes: 3 additions & 1 deletion transactions/user/setup_account.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import NonFungibleToken from 0xNFTADDRESS
import TopShot from 0xTOPSHOTADDRESS
import MetadataViews from 0xMETADATAVIEWSADDRESS

// This transaction sets up an account to use Top Shot
// by storing an empty moment collection and creating
Expand All @@ -18,7 +20,7 @@ transaction {
acct.save(<-collection, to: /storage/MomentCollection)

// create a public capability for the collection
acct.link<&{TopShot.MomentCollectionPublic}>(/public/MomentCollection, target: /storage/MomentCollection)
acct.link<&{NonFungibleToken.CollectionPublic, TopShot.MomentCollectionPublic, MetadataViews.ResolverCollection}>(/public/MomentCollection, target: /storage/MomentCollection)
}
}
}

0 comments on commit af0924d

Please sign in to comment.