Skip to content

Commit

Permalink
contracts: Remove dependency on flow-go-sdk (#18)
Browse files Browse the repository at this point in the history
* contracts: Remove dependency on flow-go-sdk

* Update contracts.go
  • Loading branch information
psiemens authored May 24, 2020
1 parent 8c7be16 commit 45af44e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
20 changes: 10 additions & 10 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package contracts

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../src/contracts -o assets.go -pkg contracts -nometadata -nomemcopy ../src/contracts
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../src/contracts -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../src/contracts

import (
"strings"

"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-ft/contracts/internal/assets"
)

const (
FungibleTokenContractFilename = "FungibleToken.cdc"
FlowTokenContractFilename = "FlowToken.cdc"
defaultFungibleTokenAddress = "02"
fungibleTokenFilename = "FungibleToken.cdc"
flowTokenFilename = "FlowToken.cdc"
defaultFungibleTokenAddress = "02"
)

// FungibleToken returns the FungibleToken contract interface.
func FungibleToken() []byte {
return MustAsset(FungibleTokenContractFilename)
return assets.MustAsset(fungibleTokenFilename)
}

// FlowToken returns the FlowToken contract. importing the
// FlowToken returns the FlowToken contract.
//
// The returned contract will import the FungibleToken contract from the specified address.
func FlowToken(fungibleTokenAddress flow.Address) []byte {
code := MustAssetString(FlowTokenContractFilename)
func FlowToken(fungibleTokenAddr string) []byte {
code := assets.MustAssetString(flowTokenFilename)

code = strings.ReplaceAll(
code,
"0x"+defaultFungibleTokenAddress,
"0x"+fungibleTokenAddress.Hex(),
"0x"+fungibleTokenAddr,
)

return []byte(code)
Expand Down
9 changes: 6 additions & 3 deletions contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package contracts_test
import (
"testing"

"github.com/onflow/flow-ft/contracts"
"github.com/onflow/flow-go-sdk"
"github.com/stretchr/testify/assert"

"github.com/onflow/flow-ft/contracts"
)

var addrA = flow.HexToAddress("0A")

func TestFungibleTokenContract(t *testing.T) {
contract := contracts.FungibleToken()
assert.NotNil(t, contract)
}

func TestFlowTokenContract(t *testing.T) {
contract := contracts.FlowToken(flow.Address{0x3})
contract := contracts.FlowToken(addrA.Hex())
assert.NotNil(t, contract)
assert.Contains(t, string(contract), "0x03")
assert.Contains(t, string(contract), addrA.Hex())
}

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

0 comments on commit 45af44e

Please sign in to comment.