diff --git a/contracts/contracts.go b/contracts/contracts.go index 46eaa0e0..ee846cf3 100644 --- a/contracts/contracts.go +++ b/contracts/contracts.go @@ -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( @@ -69,6 +69,12 @@ func CustomToken(fungibleTokenAddr, tokenName string) []byte { tokenName, ) + code = strings.ReplaceAll( + code, + "exampleToken", + storageName, + ) + return []byte(code) } @@ -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( @@ -105,5 +111,11 @@ func CustomTokenForwarding(fungibleTokenAddr, tokenName string) []byte { tokenName, ) + code = strings.ReplaceAll( + code, + "exampleToken", + storageName, + ) + return []byte(code) } diff --git a/contracts/contracts_test.go b/contracts/contracts_test.go index 9a4e216b..4bf624f0 100644 --- a/contracts/contracts_test.go +++ b/contracts/contracts_test.go @@ -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()) } @@ -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()) } diff --git a/test/token_test.go b/test/token_test.go index 20396d55..7e53b06b 100644 --- a/test/token_test.go +++ b/test/token_test.go @@ -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) @@ -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) @@ -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)) + }) }