Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Nov 14, 2023
1 parent 6386e69 commit 57f3aa1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var (
depositAmountCoin = sdk.NewCoin(uctkDenom, depositAmount)
feesAmountCoin = sdk.NewCoin(photonDenom, feesAmount)
proposalCounter = 0
certificateCounter = 0
shieldPoolCounter = 0
shieldPurchaseCounter = 0
bountyProgramCounter = 0
Expand Down Expand Up @@ -173,12 +172,16 @@ func (s *IntegrationTestSuite) initNodes(c *chain) {
// initialize a genesis file for the first validator
val0ConfigDir := c.validators[0].configDir()
for _, val := range c.validators {
s.T().Logf("validator %s : %s", val.moniker, val.keyInfo.GetAddress())
s.Require().NoError(
addGenesisAccount(val0ConfigDir, "", initBalanceStr, val.keyInfo.GetAddress()),
)
s.Require().NoError(
addCertifierAccount(val0ConfigDir, "", val.keyInfo.GetAddress()),
)
s.Require().NoError(
addCertificateAccount(val0ConfigDir, "", val.keyInfo.GetAddress().String(), val.keyInfo.GetAddress()),
)
}
for _, val := range c.accounts {
s.T().Logf("Account %s : %s", val.moniker, val.keyInfo.GetAddress())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *IntegrationTestSuite) TestCoreShield() {
// Validate certificate status
s.Require().Eventually(
func() bool {
res, err := queryCertificate(chainAAPIEndpoint, certificateCounter)
res, err := queryCertificate(chainAAPIEndpoint, int(certificateCounter))
s.Require().NoError(err)
return bytes.Contains(res.Certificate.Content.GetValue(), []byte(validatorAAddr.String()))
},
Expand Down
41 changes: 38 additions & 3 deletions tests/e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/gogo/protobuf/proto"

tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -19,6 +20,8 @@ import (
certtypes "github.com/shentufoundation/shentu/v2/x/cert/types"
)

var certificateCounter uint64 = 0

func getGenDoc(path string) (*tmtypes.GenesisDoc, error) {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand Down Expand Up @@ -132,6 +135,38 @@ func addCertifierAccount(path, moniker string, accAddr sdk.AccAddress) error {
certifier := certtypes.Certifier{
Address: accAddr.String(),
}
certGenState.Certifiers = append(certGenState.Certifiers, certifier)

certGenStateBz, err := cdc.MarshalJSON(&certGenState)
if err != nil {
return fmt.Errorf("failed to marshal cert genesis state: %w", err)
}

appState[certtypes.ModuleName] = certGenStateBz
appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
}

genDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(genDoc, genFile)
}

func addCertificateAccount(path, moniker, certifier string, accAddr sdk.AccAddress) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
config.SetRoot(path)
config.Moniker = moniker

certificateCounter++

genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

certGenState := certtypes.GetGenesisStateFromAppState(cdc, appState)

content := certtypes.AssembleContent("bountyadmin", accAddr.String())
msg, ok := content.(proto.Message)
Expand All @@ -140,15 +175,15 @@ func addCertifierAccount(path, moniker string, accAddr sdk.AccAddress) error {
}
any, err := codectypes.NewAnyWithValue(msg)
certificate := certtypes.Certificate{
CertificateId: 1,
CertificateId: certificateCounter,
Content: any,
CompilationContent: nil,
Description: "",
Certifier: accAddr.String(),
Certifier: certifier,
}

certGenState.Certifiers = append(certGenState.Certifiers, certifier)
certGenState.Certificates = append(certGenState.Certificates, certificate)
certGenState.NextCertificateId = certificateCounter + 1

certGenStateBz, err := cdc.MarshalJSON(&certGenState)
if err != nil {
Expand Down

0 comments on commit 57f3aa1

Please sign in to comment.