Skip to content

Commit

Permalink
replace storage name (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan authored Jun 5, 2020
1 parent 755c0dd commit dde8b46
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
16 changes: 14 additions & 2 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ExampleToken(fungibleTokenAddr string) []byte {
// CustomToken returns the ExampleToken contract with a custom name.
//
// The returned contract will import the FungibleToken interface from the specified address.
func CustomToken(fungibleTokenAddr, tokenName string) []byte {
func CustomToken(fungibleTokenAddr, tokenName, storageName string) []byte {
code := assets.MustAssetString(exampleTokenFilename)

code = strings.ReplaceAll(
Expand All @@ -69,6 +69,12 @@ func CustomToken(fungibleTokenAddr, tokenName string) []byte {
tokenName,
)

code = strings.ReplaceAll(
code,
"exampleToken",
storageName,
)

return []byte(code)
}

Expand All @@ -90,7 +96,7 @@ func TokenForwarding(fungibleTokenAddr string) []byte {
// CustomTokenForwarding returns the TokenForwarding contract for a custom token
//
// The returned contract will import the FungibleToken interface from the specified address.
func CustomTokenForwarding(fungibleTokenAddr, tokenName string) []byte {
func CustomTokenForwarding(fungibleTokenAddr, tokenName, storageName string) []byte {
code := assets.MustAssetString(tokenForwardingFilename)

code = strings.ReplaceAll(
Expand All @@ -105,5 +111,11 @@ func CustomTokenForwarding(fungibleTokenAddr, tokenName string) []byte {
tokenName,
)

code = strings.ReplaceAll(
code,
"exampleToken",
storageName,
)

return []byte(code)
}
4 changes: 2 additions & 2 deletions contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestExampleTokenContract(t *testing.T) {
}

func TestCustomExampleTokenContract(t *testing.T) {
contract := contracts.CustomToken(addrA.Hex(), "UtilityCoin")
contract := contracts.CustomToken(addrA.Hex(), "UtilityCoin", "utilityCoin")
assert.NotNil(t, contract)
assert.Contains(t, string(contract), addrA.Hex())
}
Expand All @@ -41,7 +41,7 @@ func TestTokenForwardingContract(t *testing.T) {
}

func TestCustomTokenForwardingContract(t *testing.T) {
contract := contracts.CustomTokenForwarding(addrA.Hex(), "UtilityCoin")
contract := contracts.CustomTokenForwarding(addrA.Hex(), "UtilityCoin", "utilityCoin")
assert.NotNil(t, contract)
assert.Contains(t, string(contract), addrA.Hex())
}
28 changes: 26 additions & 2 deletions test/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestCreateCustomToken(t *testing.T) {

accountKeys := test.AccountKeyGenerator()

exampleTokenAccountKey, _ := accountKeys.NewWithSigner()
exampleTokenAccountKey, tokenSigner := accountKeys.NewWithSigner()
// Should be able to deploy a contract as a new account with no keys.
fungibleTokenCode := contracts.FungibleToken()
fungibleAddr, err := b.CreateAccount(nil, fungibleTokenCode)
Expand All @@ -390,7 +390,7 @@ func TestCreateCustomToken(t *testing.T) {
_, err = b.CommitBlock()
assert.NoError(t, err)

exampleTokenCode := contracts.CustomToken(fungibleAddr.String(), "UtilityCoin")
exampleTokenCode := contracts.CustomToken(fungibleAddr.String(), "UtilityCoin", "utilityCoin")

tokenAddr, err := b.CreateAccount([]*flow.AccountKey{exampleTokenAccountKey}, exampleTokenCode)
assert.NoError(t, err)
Expand Down Expand Up @@ -420,4 +420,28 @@ func TestCreateCustomToken(t *testing.T) {

executeScriptAndCheck(t, b, GenerateInspectSupplyScript(fungibleAddr, tokenAddr, "UtilityCoin", 1000))
})

t.Run("Should mint tokens, deposit, and update balance and total supply", func(t *testing.T) {
tx := flow.NewTransaction().
SetScript(GenerateMintTokensScript(fungibleAddr, tokenAddr, joshAddress, "UtilityCoin", "utilityCoin", 50)).
SetGasLimit(100).
SetProposalKey(b.ServiceKey().Address, b.ServiceKey().ID, b.ServiceKey().SequenceNumber).
SetPayer(b.ServiceKey().Address).
AddAuthorizer(tokenAddr)

signAndSubmit(
t, b, tx,
[]flow.Address{b.ServiceKey().Address, tokenAddr},
[]crypto.Signer{b.ServiceKey().Signer(), tokenSigner},
false,
)

// Assert that the vaults' balances are correct
executeScriptAndCheck(t, b, GenerateInspectVaultScript(fungibleAddr, tokenAddr, tokenAddr, "UtilityCoin", "utilityCoin", 1000))

// Assert that the vaults' balances are correct
executeScriptAndCheck(t, b, GenerateInspectVaultScript(fungibleAddr, tokenAddr, joshAddress, "UtilityCoin", "utilityCoin", 50))

executeScriptAndCheck(t, b, GenerateInspectSupplyScript(fungibleAddr, tokenAddr, "UtilityCoin", 1050))
})
}

0 comments on commit dde8b46

Please sign in to comment.