Skip to content

Commit 0e04489

Browse files
authored
Merge pull request #62 from flow-hydraulics/testnet-deploy
Testnet deploy
2 parents 5c0e932 + 9a82e62 commit 0e04489

7 files changed

Lines changed: 111 additions & 34 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ jobs:
2222
RPC_ADDRESS: localhost:3569
2323
NON_FUNGIBLE_TOKEN_ADDRESS: f8d6e0586b0a20c7
2424
EXAMPLE_NFT_ADDRESS: 01cf0e2f2f715450
25+
PACKNFT_ADDRESS: 01cf0e2f2f715450
2526
PDS_ADDRESS: f3fcd2c1a78f5eee
2627
FLOW_PDS_ADMIN_ADDRESS: f3fcd2c1a78f5eee
2728
FLOW_PDS_ADMIN_PRIVATE_KEY: 9c687961e7a1abe1e445830e7ec118ffd1e2a0449cf705f5476b3f100e94dc29
2829
FLOW_PDS_ACCESS_API_HOST: localhost:3569
30+
TESTNET_OWNER: ${{ secrets.TESTNET_OWNER}}
31+
TESTNET_ISSUER: ${{ secrets.TESTNET_ISSUER}}
32+
TESTNET_PDS: ${{ secrets.TESTNET_PDS}}
2933
run: ./tests-with-emulator.sh

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# export vars from root env file
2+
ifneq (,$(wildcard ./.env.test))
3+
include .env.test
4+
export
5+
endif
6+
17
.PHONY: dev
28
dev: up deploy
39

@@ -26,6 +32,14 @@ test:
2632
@go test ./service/... -v
2733
@go test -v
2834

35+
.PHONY: test-contracts
36+
test-contracts:
37+
@go test ./go-contracts/contracts_test.go -v
38+
39+
.PHONY: tests-with-emulator
40+
tests-with-emulator:
41+
./tests-with-emulator.sh
42+
2943
.PHONY: test-clean
3044
test-clean: clean-testcache test
3145

env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#keys (ALWAYS required because flow.json will not parse correctly otherwise)
2+
TESTNET_PDS=
3+
TESTNET_OWNER=
4+
TESTNET_ISSUER=
5+
6+
# # Emulator
7+
# # --------
18
FLOW_PDS_DATABASE_DSN=postgresql://pds:pds@localhost:5432/pds
29
FLOW_PDS_DATABASE_TYPE=psql
310

@@ -7,4 +14,17 @@ FLOW_PDS_ADMIN_PRIVATE_KEY=9c687961e7a1abe1e445830e7ec118ffd1e2a0449cf705f5476b3
714
NETWORK=emulator
815
NON_FUNGIBLE_TOKEN_ADDRESS=f8d6e0586b0a20c7
916
EXAMPLE_NFT_ADDRESS=01cf0e2f2f715450
17+
PACKNFT_ADDRESS=01cf0e2f2f715450
1018
PDS_ADDRESS=f3fcd2c1a78f5eee
19+
20+
# # Testnet
21+
# # --------
22+
# NETWORK=testnet
23+
# FLOW_PDS_DATABASE_DSN=
24+
# FLOW_PDS_DATABASE_TYPE=
25+
# FLOW_PDS_ADMIN_ADDRESS=070704779ca994b7
26+
# FLOW_PDS_ADMIN_PRIVATE_KEY=
27+
# NON_FUNGIBLE_TOKEN_ADDRESS=631e88ae7f1d7c20
28+
# EXAMPLE_NFT_ADDRESS=f534d89914579e09
29+
# PACKNFT_ADDRESS=f534d89914579e09
30+
# PDS_ADDRESS=070704779ca994b7

flow.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
"emulator-pds": {
3838
"address": "f3fcd2c1a78f5eee",
3939
"key": "9c687961e7a1abe1e445830e7ec118ffd1e2a0449cf705f5476b3f100e94dc29"
40+
},
41+
"testnet-issuer" : {
42+
"address": "f534d89914579e09",
43+
"key" : "${TESTNET_ISSUER}"
44+
},
45+
"testnet-owner" : {
46+
"address": "1153614405ad9ed6",
47+
"key" : "${TESTNET_OWNER}"
48+
},
49+
"testnet-pds" : {
50+
"address": "070704779ca994b7",
51+
"key" : "${TESTNET_PDS}"
4052
}
4153
},
4254
"deployments": {
@@ -51,6 +63,15 @@
5163
"emulator-pds": [
5264
"IPackNFT"
5365
]
66+
},
67+
"testnet": {
68+
"testnet-issuer": [
69+
"ExampleNFT"
70+
],
71+
"testnet-owner": [],
72+
"testnet-pds": [
73+
"IPackNFT"
74+
]
5475
}
5576
}
5677
}

go-contracts/contracts_test.go

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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
2122
func 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

3536
func 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

5152
func 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

7172
func 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

7980
func 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

8586
func 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

9394
func 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

108109
func 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

122131
func 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

160173
func 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

177190
func 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

198209
func 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

209220
func 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

250261
func 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

292303
func 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

341353
func 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

355367
func 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

389408
func 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)

go-contracts/deploy/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"encoding/hex"
55
"fmt"
6+
"os"
67

78
"github.com/bjartek/go-with-the-flow/v2/gwtf"
89
"github.com/flow-hydraulics/flow-pds/go-contracts/util"
@@ -15,8 +16,7 @@ func main() {
1516
jsonPath := "../flow.json"
1617
var flowJSON []string = []string{jsonPath}
1718

18-
// g := gwtf.NewGoWithTheFlow(flowJSON, os.Getenv("NETWORK"), false, 3)
19-
g := gwtf.NewGoWithTheFlow(flowJSON, "emulator", false, 3)
19+
g := gwtf.NewGoWithTheFlow(flowJSON, os.Getenv("NETWORK"), false, 3)
2020

2121
packNFT := util.ParseCadenceTemplate("../cadence-contracts/PackNFT.cdc")
2222
txFilename := "../cadence-transactions/deploy/deploy-packNFT-with-auth.cdc"

go-contracts/util/util.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package util
33
import (
44
"bytes"
55
"io/ioutil"
6+
"os"
67
"strconv"
78
"testing"
89
"time"
910

10-
// "os"
11-
1211
"text/template"
1312

1413
"fmt"
@@ -51,9 +50,8 @@ func ParseCadenceTemplate(templatePath string) []byte {
5150
}
5251

5352
// Addresss for emulator are
54-
addresses = Addresses{"f8d6e0586b0a20c7", "01cf0e2f2f715450", "01cf0e2f2f715450", "f3fcd2c1a78f5eee", "f3fcd2c1a78f5eee"}
55-
// PDS account deploys IPackNFTInterface, PDSInterface, PDS contracts
56-
// addresses = Addresses{os.Getenv("NON_FUNGIBLE_TOKEN_ADDRESS"), os.Getenv("EXAMPLE_NFT_ADDRESS"), os.Getenv("PackNFT"), os.Getenv("PDS_ADDRESS"), os.Getenv("PDS_ADDRESS")}
53+
// addresses = Addresses{"f8d6e0586b0a20c7", "01cf0e2f2f715450", "01cf0e2f2f715450", "f3fcd2c1a78f5eee", "f3fcd2c1a78f5eee"}
54+
addresses = Addresses{os.Getenv("NON_FUNGIBLE_TOKEN_ADDRESS"), os.Getenv("EXAMPLE_NFT_ADDRESS"), os.Getenv("PACKNFT_ADDRESS"), os.Getenv("PDS_ADDRESS"), os.Getenv("PDS_ADDRESS")}
5755

5856
buf := &bytes.Buffer{}
5957
err = tmpl.Execute(buf, addresses)

0 commit comments

Comments
 (0)