-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4fcf22
commit 74898bf
Showing
8 changed files
with
2,188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.PHONY: test | ||
test: | ||
$(MAKE) generate -C lib/go | ||
$(MAKE) test -C lib/go | ||
|
||
.PHONY: ci | ||
ci: | ||
$(MAKE) ci -C lib/go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.PHONY: test | ||
test: | ||
$(MAKE) test -C contracts | ||
|
||
.PHONY: generate | ||
generate: | ||
$(MAKE) generate -C contracts | ||
|
||
.PHONY: ci | ||
ci: | ||
$(MAKE) ci -C contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: generate | ||
generate: | ||
go generate | ||
|
||
.PHONY: check-tidy | ||
check-tidy: generate | ||
go mod tidy | ||
git diff --exit-code | ||
|
||
.PHONY: ci | ||
ci: check-tidy test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package contracts | ||
|
||
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../../../contracts -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../../../contracts | ||
|
||
import ( | ||
"regexp" | ||
|
||
_ "github.com/kevinburke/go-bindata" | ||
|
||
"github.com/onflow/flow-go-sdk" | ||
|
||
"github.com/onflow/random-coin-toss/lib/go/contracts/internal/assets" | ||
) | ||
|
||
var ( | ||
placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`) | ||
placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`) | ||
placeholderResolver = regexp.MustCompile(`"ViewResolver"`) | ||
placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`) | ||
placeholderRandomBeaconHistory = regexp.MustCompile(`"RandomBeaconHistory"`) | ||
placeholderPseudoRandomGenerator = regexp.MustCompile(`"PseudoRandomGenerator"`) | ||
placeholderCoinToss = regexp.MustCompile(`"CoinToss"`) | ||
|
||
) | ||
|
||
const ( | ||
filenameNonFungibleToken = "utility/NonFungibleToken.cdc" | ||
filenameFungibleToken = "utility/FungibleToken.cdc" | ||
filenameResolver = "utility/ViewResolver.cdc" | ||
filenameMetadataViews = "utility/MetadataViews.cdc" | ||
filenameRandomBeaconHistory = "RandomBeaconHistory.cdc" | ||
filenamePseudoRandomGenerator = "PseudoRandomGenerator.cdc" | ||
filenameCoinToss = "CoinToss.cdc" | ||
) | ||
|
||
// NonFungibleToken returns the NonFungibleToken contract interface. | ||
func NonFungibleToken() []byte { | ||
code := assets.MustAssetString(filenameNonFungibleToken) | ||
return []byte(code) | ||
} | ||
|
||
// FungibleToken returns the FungibleToken contract interface. | ||
func FungibleToken() []byte { | ||
return assets.MustAsset(filenameFungibleToken) | ||
} | ||
|
||
func Resolver() []byte { | ||
code := assets.MustAssetString(filenameResolver) | ||
|
||
return []byte(code) | ||
} | ||
|
||
func MetadataViews(ftAddress, nftAddress, resolverAddress flow.Address) []byte { | ||
code := assets.MustAssetString(filenameMetadataViews) | ||
|
||
code = placeholderFungibleToken.ReplaceAllString(code, "0x"+ftAddress.String()) | ||
code = placeholderNonFungibleToken.ReplaceAllString(code, "0x"+nftAddress.String()) | ||
code = placeholderResolver.ReplaceAllString(code, "0x"+resolverAddress.String()) | ||
|
||
return []byte(code) | ||
} | ||
|
||
func RandomBeaconHistory() []byte { | ||
return assets.MustAsset(filenameRandomBeaconHistory) | ||
} | ||
|
||
func PseudoRandomGenerator() []byte { | ||
return assets.MustAsset(filenamePseudoRandomGenerator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package contracts_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/onflow/flow-go-sdk/test" | ||
|
||
"github.com/onflow/random-coin-toss/lib/go/contracts" | ||
) | ||
|
||
const addrA = "0x0A" | ||
|
||
func TestNonFungibleTokenContract(t *testing.T) { | ||
contract := contracts.NonFungibleToken() | ||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestFungibleTokenContract(t *testing.T) { | ||
contract := contracts.FungibleToken() | ||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestViewResolver(t *testing.T) { | ||
addresses := test.AddressGenerator() | ||
contract := contracts.ViewResolver() | ||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestMetadataViewsContract(t *testing.T) { | ||
addresses := test.AddressGenerator() | ||
addressA := addresses.New() | ||
addressB := addresses.New() | ||
addressC := addresses.New() | ||
contract := contracts.MetadataViews(addressA, addressB, addressC) | ||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestRandomBeaconHistory(t *testing.T) { | ||
addresses := test.AddressGenerator() | ||
contract := contracts.RandomBeaconHistory() | ||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestRandomBeaconHistory(t *testing.T) { | ||
addresses := test.AddressGenerator() | ||
contract := contracts.PseudoRandomGenerator() | ||
assert.NotNil(t, contract) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/onflow/random-coin_toss/lib/go/contracts | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/kevinburke/go-bindata v3.22.0+incompatible | ||
github.com/onflow/flow-go-sdk v0.41.7-stable-cadence | ||
github.com/stretchr/testify v1.8.2 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.