44 "fmt"
55 "strconv"
66 "testing"
7+ "os"
78
89 "github.com/bjartek/go-with-the-flow/v2/gwtf"
910 "github.com/flow-hydraulics/flow-pds/go-contracts/examplenft"
@@ -19,7 +20,7 @@ import (
1920
2021// Create all required resources for different accounts
2122func TestMintExampleNFTs (t * testing.T ){
22- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
23+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
2324 mintExampleNFT := "../cadence-transactions/exampleNFT/mint_exampleNFT.cdc"
2425 mintExampleNFTCode := util .ParseCadenceTemplate (mintExampleNFT )
2526 for i := 0 ; i < 3 ; i ++ {
@@ -34,7 +35,7 @@ func TestMintExampleNFTs(t *testing.T){
3435
3536func TestCanCreateExampleCollection (t * testing.T ) {
3637// for both pds and owner
37- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
38+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
3839 setupExampleNFT := "../cadence-transactions/exampleNFT/setup_exampleNFT.cdc"
3940 setupExampleNFTCode := util .ParseCadenceTemplate (setupExampleNFT )
4041 _ , err := g .TransactionFromFile (setupExampleNFT , setupExampleNFTCode ).
@@ -50,7 +51,7 @@ func TestCanCreateExampleCollection(t *testing.T) {
5051
5152func TestCanCreatePackNFTCollection (t * testing.T ) {
5253// for both issuer and owner
53- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
54+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
5455 createPackNFTCollection := "../cadence-transactions/packNFT/create_new_packNFT_collection.cdc"
5556 createPackNFTCollectionCode := util .ParseCadenceTemplate (createPackNFTCollection )
5657 _ , err := g .
@@ -69,29 +70,29 @@ func TestCanCreatePackNFTCollection(t *testing.T) {
6970
7071
7172func TestCanCreatePackIssuer (t * testing.T ) {
72- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
73+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
7374 _ , err := pds .CreatePackIssuer (g , "issuer" )
7475 assert .NoError (t , err )
7576}
7677
7778// Setup - sharing capabilities
7879
7980func TestCannotCreateDistWithoutCap (t * testing.T ){
80- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
81+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
8182 _ , err := pds .CreateDistribution (g , "issuer" )
8283 assert .Error (t , err )
8384}
8485
8586func TestSetDistCap (t * testing.T ) {
86- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
87+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
8788 _ , err := pds .SetPackIssuerCap (g , "issuer" , "pds" )
8889 assert .NoError (t , err )
8990}
9091
9192// Create Distribution and Minting
9293
9394func TestCreateDistWithCap (t * testing.T ){
94- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
95+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
9596 currentDistId , err := pds .GetDistID (g )
9697 assert .NoError (t , err )
9798 events , err := pds .CreateDistribution (g , "issuer" )
@@ -107,7 +108,7 @@ func TestCreateDistWithCap(t *testing.T){
107108
108109func TestPDSEscrowNFTs (t * testing.T ){
109110 // This just tests to transfer all issuer example NFTs into escrow
110- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
111+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
111112 nfts , err := examplenft .GetBalance (g , "issuer" )
112113 nextDistId , err := pds .GetDistID (g )
113114 gonfts := nfts .ToGoValue ().([]interface {})
@@ -116,12 +117,24 @@ func TestPDSEscrowNFTs(t *testing.T){
116117 assert .NoError (t , err )
117118 events , err := pds .PDSWithdrawNFT (g , nextDistId - 1 , nfts , "pds" )
118119 assert .NoError (t , err )
119- assert .Len (t , events , 2 * len (gonfts ))
120+ if os .Getenv ("NETWORK" ) == "emulator" {
121+ fmt .Print ("emulator" )
122+ // For emulator there are deposit and withdraw events
123+ assert .Len (t , events , 2 * len (gonfts ))
124+ } else {
125+ fmt .Print ("testnet" )
126+ // For testnet there are deposit and withdraw and fees (withdraw, deposit, fee)
127+ assert .Len (t , events , 2 * len (gonfts ) + 3 )
128+ }
120129}
121130
122131func TestPDSMintPackNFTs (t * testing.T ){
123- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
124- toHash := "f24dfdf9911df152,A.01cf0e2f2f715450.ExampleNFT.0,A.01cf0e2f2f715450.ExampleNFT.3"
132+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os .Getenv ("NETWORK" ), false , 3 )
133+ addr := g .Account ("issuer" ).Address ().String ()
134+ toHash := "f24dfdf9911df152,A." + addr + ".ExampleNFT.0,A." + addr + ".ExampleNFT.3"
135+
136+ fmt .Printf ("toHash: %s" , toHash )
137+
125138 hash , err := util .GetHash (g , toHash )
126139 assert .NoError (t , err )
127140
@@ -158,7 +171,7 @@ func TestPDSMintPackNFTs(t *testing.T){
158171// Sold Pack Transfer to Owner
159172
160173func TestTransfeToOwner (t * testing.T ){
161- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
174+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
162175 nextPackNFTId , err := packnft .GetTotalPacks (g )
163176 assert .NoError (t , err )
164177
@@ -175,15 +188,13 @@ func TestTransfeToOwner(t *testing.T){
175188// Reveal
176189
177190func TestOwnerRevealReq (t * testing.T ){
178- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
191+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
179192 nextPackNFTId , err := packnft .GetTotalPacks (g )
180193 currentPack := nextPackNFTId - 1
181194 assert .NoError (t , err )
182195
183196 events , err := packnft .OwnerRevealReq (g , currentPack )
184197 assert .NoError (t , err )
185- // There should only be 1 event
186- assert .Len (t , events , 1 )
187198
188199 util .NewExpectedPackNFTEvent ("RevealRequest" ).
189200 AddField ("id" , strconv .Itoa (int (currentPack ))).
@@ -196,7 +207,7 @@ func TestOwnerRevealReq(t *testing.T){
196207}
197208
198209func TestOwnerCannotOpenWithoutRevealed (t * testing.T ){
199- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
210+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
200211 nextPackNFTId , err := packnft .GetTotalPacks (g )
201212 currentPack := nextPackNFTId - 1
202213 assert .NoError (t , err )
@@ -207,7 +218,7 @@ func TestOwnerCannotOpenWithoutRevealed(t *testing.T){
207218}
208219
209220func TestPDSCannotRevealwithWrongSalt (t * testing.T ){
210- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
221+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
211222 nextPackNFTId , err := packnft .GetTotalPacks (g )
212223 assert .NoError (t , err )
213224 currentPack := nextPackNFTId - 1
@@ -248,7 +259,7 @@ func TestPDSCannotRevealwithWrongSalt(t *testing.T){
248259}
249260
250261func TestPDSCannotRevealwithWrongNFTs (t * testing.T ){
251- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
262+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
252263 nextPackNFTId , err := packnft .GetTotalPacks (g )
253264 assert .NoError (t , err )
254265 currentPack := nextPackNFTId - 1
@@ -290,7 +301,7 @@ func TestPDSCannotRevealwithWrongNFTs(t *testing.T){
290301}
291302
292303func TestPDSRevealPackNFTs (t * testing.T ){
293- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
304+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
294305 nextPackNFTId , err := packnft .GetTotalPacks (g )
295306 assert .NoError (t , err )
296307 currentPack := nextPackNFTId - 1
@@ -300,7 +311,8 @@ func TestPDSRevealPackNFTs(t *testing.T){
300311 assert .NoError (t , err )
301312
302313 salt := "f24dfdf9911df152"
303- nftString := "A.01cf0e2f2f715450.ExampleNFT.0,A.01cf0e2f2f715450.ExampleNFT.3"
314+ addr := g .Account ("issuer" ).Address ().String ()
315+ nftString := "A." + addr + ".ExampleNFT.0,A." + addr + ".ExampleNFT.3"
304316 var addrs []cadence.Value
305317 var name []cadence.Value
306318 var ids []cadence.Value
@@ -339,7 +351,7 @@ func TestPDSRevealPackNFTs(t *testing.T){
339351// Open
340352
341353func TestOwnerOpenReq (t * testing.T ){
342- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
354+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
343355 nextPackNFTId , err := packnft .GetTotalPacks (g )
344356 currentPack := nextPackNFTId - 1
345357 assert .NoError (t , err )
@@ -353,7 +365,7 @@ func TestOwnerOpenReq(t *testing.T){
353365}
354366
355367func TestPDSOpenPackNFTs (t * testing.T ){
356- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
368+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
357369 nextPackNFTId , err := packnft .GetTotalPacks (g )
358370 assert .NoError (t , err )
359371 currentPack := nextPackNFTId - 1
@@ -378,26 +390,34 @@ func TestPDSOpenPackNFTs(t *testing.T){
378390 AddField ("id" , strconv .Itoa (int (currentPack ))).
379391 AssertEqual (t , events [0 ])
380392
381- // each NFT goes through withdraw and deposit events
382- assert .Len (t , events , (2 * len (gonfts )) + 1 )
393+ if os .Getenv ("NETWORK" ) == "emulator" {
394+ fmt .Print ("emulator" )
395+ // each NFT goes through withdraw and deposit events
396+ assert .Len (t , events , (2 * len (gonfts ) + 1 ))
397+ } else {
398+ fmt .Print ("testnet" )
399+ // each NFT goes through withdraw and deposit events and 3 events for fees
400+ assert .Len (t , events , (2 * len (gonfts ) + 1 + 3 ))
401+ }
383402
384403 status , err := packnft .GetPackStatus (g , currentPack )
385404 assert .NoError (t , err )
386405 assert .Equal (t , "Opened" , status )
387406}
388407
389408func TestPublicVerify (t * testing.T ) {
390- g := gwtf .NewGoWithTheFlow (util .FlowJSON , "emulator" , false , 3 )
409+ g := gwtf .NewGoWithTheFlow (util .FlowJSON , os . Getenv ( "NETWORK" ) , false , 3 )
391410 nextPackNFTId , err := packnft .GetTotalPacks (g )
392411 assert .NoError (t , err )
393412 currentPack := nextPackNFTId - 1
394413
395- nfts := "A.01cf0e2f2f715450.ExampleNFT.0,A.01cf0e2f2f715450.ExampleNFT.3"
414+ addr := g .Account ("issuer" ).Address ().String ()
415+ nfts := "A." + addr + ".ExampleNFT.0,A." + addr + ".ExampleNFT.3"
396416 v , err := packnft .Verify (g , currentPack , nfts )
397417 assert .NoError (t , err )
398418 assert .Equal (t , true , v )
399419
400- notNfts := "A.01cf0e2f2f715450 .ExampleNFT.1 ,A.01cf0e2f2f715450 .ExampleNFT.3 "
420+ notNfts := "A." + addr + " .ExampleNFT.2 ,A." + addr + " .ExampleNFT.4 "
401421 v , err = packnft .Verify (g , currentPack , notNfts )
402422 assert .NoError (t , err )
403423 assert .Equal (t , false , v )
0 commit comments