From fd4ce30d819fddcc843b1b8a678d4122d4569618 Mon Sep 17 00:00:00 2001 From: Josh Hannan Date: Thu, 1 Feb 2024 12:40:03 -0600 Subject: [PATCH] remove some go tests --- coverage.json | 238 +++++++++++++++++++----------- lib/go/test/forwarding_test.go | 217 --------------------------- lib/go/test/token_test_helpers.go | 13 ++ 3 files changed, 167 insertions(+), 301 deletions(-) delete mode 100644 lib/go/test/forwarding_test.go diff --git a/coverage.json b/coverage.json index d4d05ab..9664efd 100644 --- a/coverage.json +++ b/coverage.json @@ -1,9 +1,9 @@ { "coverage": { - "A.0000000000000007.ExampleToken": { + "./contracts/ExampleToken.cdc": { "line_hits": { - "104": 0, - "106": 0, + "104": 11, + "106": 11, "113": 0, "117": 0, "121": 0, @@ -12,18 +12,18 @@ "128": 0, "132": 0, "137": 0, - "151": 0, - "152": 0, - "165": 0, - "166": 0, - "167": 0, - "168": 0, + "151": 2, + "152": 2, + "165": 2, + "166": 2, + "167": 2, + "168": 2, "179": 0, "18": 0, - "194": 0, - "195": 0, - "196": 0, - "208": 0, + "194": 1, + "195": 1, + "196": 1, + "208": 1, "21": 0, "212": 1, "214": 1, @@ -35,18 +35,18 @@ "229": 1, "231": 1, "232": 1, - "25": 0, - "28": 0, - "54": 1, - "55": 1, - "56": 1, - "57": 1, - "58": 1, - "63": 0, - "64": 0, - "66": 0, - "70": 0, - "79": 0, + "25": 11, + "28": 11, + "54": 5, + "55": 5, + "56": 5, + "57": 5, + "58": 5, + "63": 1, + "64": 1, + "66": 1, + "70": 1, + "79": 11, "81": 0, "86": 0, "92": 0, @@ -55,19 +55,10 @@ "missed_lines": [ 18, 21, - 25, - 28, - 63, - 64, - 66, - 70, - 79, 81, 86, 92, 93, - 104, - 106, 113, 117, 121, @@ -76,79 +67,158 @@ 128, 132, 137, - 151, - 152, - 165, - 166, + 179 + ], + "statements": 49, + "percentage": "69.4%" + }, + "./contracts/FungibleToken.cdc": { + "line_hits": { + "100": 2, + "148": 1, + "151": 1, + "162": 0, + "163": 0, + "167": 0, + "173": 0, + "181": 3, + "185": 2, + "189": 5, + "200": 2, + "202": 2, + "205": 6, + "214": 0, + "223": 1, + "224": 1, + "98": 2 + }, + "missed_lines": [ + 162, + 163, 167, + 173, + 214 + ], + "statements": 17, + "percentage": "70.6%" + }, + "./contracts/FungibleTokenMetadataViews.cdc": { + "line_hits": { + "102": 0, + "103": 0, + "104": 0, + "107": 0, + "145": 11, + "146": 11, + "148": 11, + "149": 11, + "150": 11, + "151": 11, + "152": 11, + "153": 11, + "163": 0, + "164": 0, + "165": 0, + "168": 0, + "176": 0, + "27": 0, + "28": 0, + "38": 0, + "39": 0, + "40": 0, + "42": 0, + "87": 0, + "88": 0, + "89": 0, + "90": 0, + "91": 0, + "92": 0 + }, + "missed_lines": [ + 27, + 28, + 38, + 39, + 40, + 42, + 87, + 88, + 89, + 90, + 91, + 92, + 102, + 103, + 104, + 107, + 163, + 164, + 165, 168, - 179, - 194, - 195, - 196, - 208 + 176 ], - "statements": 49, - "percentage": "30.6%" + "statements": 29, + "percentage": "27.6%" }, - "A.0000000000000007.PrivateReceiverForwarder": { + "./contracts/utility/Burner.cdc": { "line_hits": { + "24": 1, + "25": 1, + "26": 1, + "27": 0, + "28": 0, + "29": 0, + "30": 0, + "32": 0, + "33": 0, + "34": 0, "35": 0, + "36": 0, "37": 0, "39": 0, - "41": 0, - "43": 0, - "48": 0, - "50": 0, - "57": 0, - "64": 0, - "66": 0, - "70": 0, - "77": 1, - "79": 1, - "80": 1, - "82": 1 + "41": 0 }, "missed_lines": [ + 27, + 28, + 29, + 30, + 32, + 33, + 34, 35, + 36, 37, 39, - 41, - 43, - 48, - 50, - 57, - 64, - 66, - 70 + 41 ], "statements": 15, - "percentage": "26.7%" + "percentage": "20.0%" } }, "excluded_locations": [ - "s.7465737400000000000000000000000000000000000000000000000000000000", - "A.0000000000000001.FlowStorageFees", - "A.0000000000000001.FlowEpoch", - "A.0000000000000001.FlowIDTableStaking", + "A.0000000000000002.FungibleToken", + "A.0000000000000001.MetadataViews", + "A.0000000000000001.FlowServiceAccount", + "I.Crypto", + "I.BlockchainHelpers", + "A.0000000000000004.FlowFees", "A.0000000000000002.FungibleTokenMetadataViews", "A.0000000000000001.NonFungibleToken", + "A.0000000000000001.ViewResolver", + "A.0000000000000003.FlowToken", + "A.0000000000000001.FlowClusterQC", + "A.0000000000000001.FlowIDTableStaking", + "A.0000000000000001.ExampleNFT", "A.0000000000000001.FlowDKG", + "A.0000000000000001.FlowStorageFees", + "A.0000000000000001.FlowEpoch", + "I.Test", + "A.0000000000000001.StakingProxy", "A.0000000000000001.RandomBeaconHistory", "A.0000000000000001.NodeVersionBeacon", - "A.0000000000000003.FlowToken", + "s.7465737400000000000000000000000000000000000000000000000000000000", "A.0000000000000001.FlowStakingCollection", - "I.Test", - "A.0000000000000001.ExampleNFT", - "I.Crypto", - "A.0000000000000001.StakingProxy", - "A.0000000000000001.FlowServiceAccount", - "A.0000000000000001.ViewResolver", - "A.0000000000000001.MetadataViews", - "A.0000000000000002.FungibleToken", - "A.0000000000000004.FlowFees", - "A.0000000000000001.LockedTokens", - "A.0000000000000001.FlowClusterQC", - "I.BlockchainHelpers" + "A.0000000000000001.LockedTokens" ] } \ No newline at end of file diff --git a/lib/go/test/forwarding_test.go b/lib/go/test/forwarding_test.go deleted file mode 100644 index a151668..0000000 --- a/lib/go/test/forwarding_test.go +++ /dev/null @@ -1,217 +0,0 @@ -package test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/onflow/cadence" - jsoncdc "github.com/onflow/cadence/encoding/json" - "github.com/onflow/cadence/runtime/common" - "github.com/onflow/flow-go-sdk" - "github.com/onflow/flow-go-sdk/crypto" - - "github.com/onflow/flow-ft/lib/go/contracts" - "github.com/onflow/flow-ft/lib/go/templates" -) - -func TestPrivateForwarder(t *testing.T) { - b, adapter, accountKeys := newTestSetup(t) - - serviceSigner, _ := b.ServiceKey().Signer() - - env := templates.Environment{} - - exampleTokenAccountKey, exampleTokenSigner := accountKeys.NewWithSigner() - exampleTokenAddr := deployTokenContracts(b, adapter, t, []*flow.AccountKey{exampleTokenAccountKey}, &env) - - forwardingCode := contracts.PrivateReceiverForwarder(env.FungibleTokenAddress) - cadenceCode := bytesToCadenceArray(forwardingCode) - - name, _ := cadence.NewString("PrivateReceiverForwarder") - - tx := flow.NewTransaction(). - SetScript(templates.GenerateDeployPrivateForwardingScript()). - SetGasLimit(100). - SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber). - SetPayer(b.ServiceKey().Address). - AddAuthorizer(exampleTokenAddr). - AddRawArgument(jsoncdc.MustEncode(name)). - AddRawArgument(jsoncdc.MustEncode(cadenceCode)) - - _ = tx.AddArgument(cadence.Path{Domain: common.PathDomainStorage, Identifier: "privateForwardingSender"}) - _ = tx.AddArgument(cadence.Path{Domain: common.PathDomainStorage, Identifier: "privateForwardingStorage"}) - _ = tx.AddArgument(cadence.Path{Domain: common.PathDomainPublic, Identifier: "privateForwardingPublic"}) - - signAndSubmit( - t, b, tx, - []flow.Address{b.ServiceKey().Address, exampleTokenAddr}, - []crypto.Signer{serviceSigner, exampleTokenSigner}, - false, - ) - - env.PrivateForwardingAddress = env.ExampleTokenAddress - - joshAccountKey, joshSigner := accountKeys.NewWithSigner() - joshAddress, _ := adapter.CreateAccount(context.Background(), []*flow.AccountKey{joshAccountKey}, nil) - - t.Run("Should be able to set up an account to accept private deposits", func(t *testing.T) { - - script := templates.GenerateSetupAccountPrivateForwarderScript(env) - - tx := flow.NewTransaction(). - SetScript(script). - SetGasLimit(100). - SetProposalKey( - b.ServiceKey().Address, - b.ServiceKey().Index, - b.ServiceKey().SequenceNumber, - ). - SetPayer(b.ServiceKey().Address). - AddAuthorizer(joshAddress) - - signAndSubmit( - t, b, tx, - []flow.Address{ - b.ServiceKey().Address, - joshAddress, - }, - []crypto.Signer{ - serviceSigner, - joshSigner, - }, - false, - ) - }) - - t.Run("Should be able to transfer private tokens to an account", func(t *testing.T) { - - recipient1Address := cadence.Address(joshAddress) - recipient1Amount := CadenceUFix64("300.0") - - pair := cadence.KeyValuePair{Key: recipient1Address, Value: recipient1Amount} - recipientPairs := make([]cadence.KeyValuePair, 1) - recipientPairs[0] = pair - - script := templates.GenerateTransferPrivateManyAccountsScript(env) - tx = flow.NewTransaction(). - SetScript(script). - SetGasLimit(100). - SetProposalKey( - b.ServiceKey().Address, - b.ServiceKey().Index, - b.ServiceKey().SequenceNumber, - ). - SetPayer(b.ServiceKey().Address). - AddAuthorizer(exampleTokenAddr) - - _ = tx.AddArgument(cadence.NewDictionary(recipientPairs)) - - signAndSubmit( - t, b, tx, - []flow.Address{ - b.ServiceKey().Address, - exampleTokenAddr, - }, - []crypto.Signer{ - serviceSigner, - exampleTokenSigner, - }, - false, - ) - - // Assert that the vaults' balances are correct - script = templates.GenerateInspectVaultScript(env) - result, err := b.ExecuteScript( - script, - [][]byte{ - jsoncdc.MustEncode(cadence.Address(exampleTokenAddr)), - }, - ) - require.NoError(t, err) - if !assert.True(t, result.Succeeded()) { - t.Log(result.Error.Error()) - } - balance := result.Value - assertEqual(t, CadenceUFix64("700.0"), balance) - - script = templates.GenerateInspectVaultScript(env) - result, err = b.ExecuteScript( - script, - [][]byte{ - jsoncdc.MustEncode(cadence.Address(joshAddress)), - }, - ) - require.NoError(t, err) - if !assert.True(t, result.Succeeded()) { - t.Log(result.Error.Error()) - } - balance = result.Value - assertEqual(t, CadenceUFix64("300.0"), balance) - - script = templates.GenerateInspectSupplyScript(env) - supply := executeScriptAndCheck(t, b, script, nil) - assertEqual(t, CadenceUFix64("1000.0"), supply) - }) - - t.Run("Should be able to create a new account with private forwarder", func(t *testing.T) { - - script := templates.GenerateCreateAccountPrivateForwarderScript(env) - tx = flow.NewTransaction(). - SetScript(script). - SetGasLimit(100). - SetProposalKey( - b.ServiceKey().Address, - b.ServiceKey().Index, - b.ServiceKey().SequenceNumber, - ). - SetPayer(b.ServiceKey().Address). - AddAuthorizer(exampleTokenAddr) - - signAndSubmit( - t, b, tx, - []flow.Address{ - b.ServiceKey().Address, - exampleTokenAddr, - }, - []crypto.Signer{ - serviceSigner, - exampleTokenSigner, - }, - false, - ) - - }) - - t.Run("Should be able to do account setup a second time without change", func(t *testing.T) { - - script := templates.GenerateSetupAccountPrivateForwarderScript(env) - - // send the same transaction one more time for the same address that's already set up - tx := flow.NewTransaction(). - SetScript(script). - SetGasLimit(100). - SetProposalKey( - b.ServiceKey().Address, - b.ServiceKey().Index, - b.ServiceKey().SequenceNumber, - ). - SetPayer(b.ServiceKey().Address). - AddAuthorizer(joshAddress) - - signAndSubmit( - t, b, tx, - []flow.Address{ - b.ServiceKey().Address, - joshAddress, - }, - []crypto.Signer{ - serviceSigner, - joshSigner, - }, - false, - ) - }) -} diff --git a/lib/go/test/token_test_helpers.go b/lib/go/test/token_test_helpers.go index 290b3fb..bba165b 100644 --- a/lib/go/test/token_test_helpers.go +++ b/lib/go/test/token_test_helpers.go @@ -156,6 +156,19 @@ func deployTokenContracts( assert.NoError(t, err) env.SwitchboardAddress = switchboardAddr.Hex() + // // Deploy the PrivateReceiverForwarder contract + // privateRecFor := contracts.PrivateReceiverForwarder(fungibleAddr.String()) + // _, err = adapter.CreateAccount(context.Background(), + // key, + // []sdktemplates.Contract{ + // { + // Name: "PrivateReceiverForwarder", + // Source: string(privateRecFor), + // }, + // }, + // ) + // assert.NoError(t, err) + _, err = b.CommitBlock() assert.NoError(t, err)