Skip to content

Commit

Permalink
Update fungible token contract to v0.7.0 (#362)
Browse files Browse the repository at this point in the history
* update fungible token contract

* update fungible token contract in test

* fix tests with flow-ft dependency

---------

Co-authored-by: Josh Hannan <[email protected]>
  • Loading branch information
sideninja and joshuahannan authored Apr 15, 2023
1 parent 28fe222 commit c016478
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 154 deletions.
2 changes: 1 addition & 1 deletion lib/go/contracts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/kevinburke/go-bindata v3.23.0+incompatible
github.com/onflow/flow-ft/lib/go/contracts v0.5.0
github.com/onflow/flow-ft/lib/go/contracts v0.7.0
github.com/stretchr/testify v1.8.0
)

Expand Down
5 changes: 2 additions & 3 deletions lib/go/contracts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onflow/flow-ft/lib/go/contracts v0.5.0 h1:Cg4gHGVblxcejfNNG5Mfj98Wf4zbY76O0Y28QB0766A=
github.com/onflow/flow-ft/lib/go/contracts v0.5.0/go.mod h1:1zoTjp1KzNnOPkyqKmWKerUyf0gciw+e6tAEt0Ks3JE=
github.com/onflow/flow-ft/lib/go/contracts v0.7.0 h1:XEKE6qJUw3luhsYmIOteXP53gtxNxrwTohgxJXCYqBE=
github.com/onflow/flow-ft/lib/go/contracts v0.7.0/go.mod h1:kTMFIySzEJJeupk+7EmXs0EJ6CBWY/MV9fv9iYQk+RU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down
6 changes: 3 additions & 3 deletions lib/go/templates/internal/assets/assets.go

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

17 changes: 17 additions & 0 deletions lib/go/templates/service_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (

const (

// FlowToken Templates
mintFlowFilename = "flowToken/mint_tokens.cdc"
getFlowBalanceFilename = "flowToken/scripts/get_balance.cdc"

// FlowStorageFees templates

changeStorageFeeParametersFilename = "storageFees/admin/set_parameters.cdc"
Expand Down Expand Up @@ -36,6 +40,19 @@ const (
setExecutionMemoryLimit = "FlowServiceAccount/set_execution_memory_limit.cdc"
)

// FlowToken Templates
func GenerateMintFlowScript(env Environment) []byte {
code := assets.MustAssetString(mintFlowFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateGetFlowBalanceScript(env Environment) []byte {
code := assets.MustAssetString(getFlowBalanceFilename)

return []byte(ReplaceAddresses(code, env))
}

// StorageFees Templates

func GenerateChangeStorageFeeParametersScript(env Environment) []byte {
Expand Down
16 changes: 8 additions & 8 deletions lib/go/test/flow_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestEpochClusters(t *testing.T) {
})

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestEpochPhaseMetadataChange(t *testing.T) {
})

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestEpochAdvance(t *testing.T) {
})

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, dkgIDs := generateNodeIDs(numEpochAccounts)
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down Expand Up @@ -552,7 +552,7 @@ func TestEpochQCDKGNodeRegistration(t *testing.T) {
rewardIncreaseFactor)

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down Expand Up @@ -644,7 +644,7 @@ func TestEpochFullNodeRegistration(t *testing.T) {
rewardIncreaseFactor)

// create new user accounts, mint tokens for them, and register them for staking
addresses, publicKeys, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, publicKeys, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForEpochs(t, b, env,
Expand Down Expand Up @@ -676,7 +676,7 @@ func TestEpochQCDKG(t *testing.T) {
rewardIncreaseFactor)

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
stakingPrivateKeys, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down Expand Up @@ -979,7 +979,7 @@ func TestEpochQCDKG(t *testing.T) {

t.Run("Can set the rewards with high fee amount, which should not increase the supply at all", func(t *testing.T) {

mintTokensForAccount(t, b, idTableAddress, "6572144.3875")
mintTokensForAccount(t, b, env, idTableAddress, "6572144.3875")

tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateDepositFeesScript(env), idTableAddress)

Expand Down Expand Up @@ -1052,7 +1052,7 @@ func TestEpochReset(t *testing.T) {
rewardIncreaseFactor)

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, accountKeys, numEpochAccounts)
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, numEpochAccounts)
ids, _, _ := generateNodeIDs(numEpochAccounts)
stakingPrivateKeys, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, numEpochAccounts)
registerNodesForStaking(t, b, env,
Expand Down
14 changes: 2 additions & 12 deletions lib/go/test/flow_idtable_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/onflow/flow-go-sdk/crypto"
"github.com/onflow/flow-go-sdk/test"

ft_templates "github.com/onflow/flow-ft/lib/go/templates"

"github.com/onflow/flow-core-contracts/lib/go/templates"
)

Expand Down Expand Up @@ -78,11 +76,7 @@ func TestManyNodesIDTable(t *testing.T) {
totalMint := numberOfNodes * nodeMintAmount
mintAmount := fmt.Sprintf("%d.0", totalMint)

script := ft_templates.GenerateMintTokensScript(
flow.HexToAddress(emulatorFTAddress),
flow.HexToAddress(emulatorFlowTokenAddress),
"FlowToken",
)
script := templates.GenerateMintFlowScript(env)

tx := createTxWithTemplateAndAuthorizer(b, script, b.ServiceKey().Address)

Expand Down Expand Up @@ -396,11 +390,7 @@ func TestUnstakeAllManyDelegatorsIDTable(t *testing.T) {

for i := 0; i < unstakeAllNumNodes; i++ {

script := ft_templates.GenerateMintTokensScript(
flow.HexToAddress(emulatorFTAddress),
flow.HexToAddress(emulatorFlowTokenAddress),
"FlowToken",
)
script := templates.GenerateMintFlowScript(env)
tx := createTxWithTemplateAndAuthorizer(b, script, b.ServiceKey().Address)

_ = tx.AddArgument(cadence.NewAddress(nodeAddresses[i]))
Expand Down
Loading

0 comments on commit c016478

Please sign in to comment.