Skip to content

Commit

Permalink
validate ict code coverage output
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jun 27, 2024
1 parent 5bcb14d commit 57b490c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
91 changes: 91 additions & 0 deletions examples/cosmos/code_coverage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package cosmos_test

import (
"context"
"os"
"testing"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

func TestCodeCoverage(t *testing.T) {
t.Parallel()

var (
ctx = context.Background()
ExternalGoCoverDir = "/tmp/interchaintest-app-coverage"
Denom = "umfx"
vals = 1
fullNodes = 0
)

cfgA := ibc.ChainConfig{
Type: "cosmos",
Name: "manifest",
ChainID: "manifest-2",
Images: []ibc.DockerImage{
{
Repository: "manifest",
Version: "v0.0.1-alpha.10",
UidGid: "1025:1025",
},
},
Bin: "manifestd",
Bech32Prefix: "manifest",
Denom: Denom,
GasPrices: "0" + Denom,
GasAdjustment: 1.3,
TrustingPeriod: "508h",
NoHostMount: false,
}

cfgA.WithCodeCoverage()

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t, zaptest.Level(zapcore.DebugLevel)), []*interchaintest.ChainSpec{
{
Name: "manifest",
Version: "local",
ChainName: cfgA.ChainID,
NumValidators: &vals,
NumFullNodes: &fullNodes,
ChainConfig: cfgA,
},
})

chains, err := cf.Chains(t.Name())
require.NoError(t, err)
chainA := chains[0].(*cosmos.CosmosChain)

client, network := interchaintest.DockerSetup(t)

ic := interchaintest.NewInterchain().
AddChain(chainA)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

// Build interchain
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))

t.Cleanup(func() {
dockerutil.CopyCoverageFromContainer(ctx, t, client, chainA.GetNode().ContainerID(), chainA.HomeDir(), ExternalGoCoverDir)

files, err := os.ReadDir(ExternalGoCoverDir)
require.NoError(t, err)
require.NotEmpty(t, files)

_ = ic.Close()
})
}
9 changes: 9 additions & 0 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"path"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -226,6 +227,14 @@ func (c ChainConfig) MergeChainSpecConfig(other ChainConfig) ChainConfig {
return c
}

// WithCodeCoverage enables Go Code Coverage from the chain node directory.
func (c *ChainConfig) WithCodeCoverage(override ...string) {
c.Env = append(c.Env, fmt.Sprintf("GOCOVERDIR=%s", path.Join("/var/cosmos-chain", c.ChainID)))
if len(override) > 0 {
c.Env = append(c.Env, override[0])
}
}

// IsFullyConfigured reports whether all required fields have been set on c.
// It is possible for some fields, such as GasAdjustment and NoHostMount,
// to be their respective zero values and for IsFullyConfigured to still report true.
Expand Down

0 comments on commit 57b490c

Please sign in to comment.