From d6d5e1fb4801b8275f28292e1a9f7c1008df9b86 Mon Sep 17 00:00:00 2001 From: Hyoung-yoon Kim Date: Wed, 13 Dec 2023 09:53:21 +0900 Subject: [PATCH] fix: workflow fix and code cleanup --- .github/workflows/test.yml | 37 +++++++++++++++++++++++-------------- DEVELOPING.md | 9 ++++++++- app/app.go | 4 +--- dockerfiles/Dockerfile.e2e | 10 ++-------- e2e/e2e_setup_test.go | 18 ++++++++++++------ e2e/genesis.go | 26 ++++++++++++++++++++++---- e2e/validator.go | 6 ++++-- go.mod | 2 +- go.sum | 4 ++++ scripts/local_setup.sh | 2 +- x/randomness/keeper/abci.go | 14 ++------------ x/staking/module.go | 1 - 12 files changed, 80 insertions(+), 53 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ae5c955..67828f1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ on: permissions: contents: read + repository-projects: read + packages: read concurrency: group: ci-${{ github.ref }}-tests @@ -19,8 +21,8 @@ jobs: build: runs-on: ubuntu-latest env: - GOPRIVATE: github.com/fabianMendez/privatemodule - GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} + GOPRIVATE: github.com/sedaprotocol/vrf-go + PAT: ${{ secrets.PAT }} strategy: matrix: arch: [amd64, arm64] @@ -49,7 +51,9 @@ jobs: env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} - - run: git config --global url.https://$GITHUB_TOKEN@github.com/.insteadOf https://github.com/ + - name: Configure private token + run: | + git config --global url."https://${PAT}@github.com/".insteadOf "https://github.com/" - name: Compile if: steps.cache-binaries.outputs.cache-hit != 'true' && env.GIT_DIFF run: | @@ -59,8 +63,8 @@ jobs: tests: runs-on: ubuntu-latest env: - GOPRIVATE: github.com/fabianMendez/privatemodule - GH_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOPRIVATE: github.com/sedaprotocol/vrf-go + PAT: ${{ secrets.PAT }} steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 @@ -69,7 +73,7 @@ jobs: check-latest: true cache: true cache-dependency-path: go.sum - - run: git config --global url.https://$GITHUB_TOKEN@github.com/.insteadOf https://github.com/ + - run: git config --global url.https://${PAT}@github.com/.insteadOf https://github.com/ - uses: technote-space/get-diff-action@v6.1.2 id: git_diff with: @@ -93,23 +97,28 @@ jobs: test-e2e: runs-on: ubuntu-latest env: - GOPRIVATE: github.com/fabianMendez/privatemodule - GH_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOPRIVATE: github.com/sedaprotocol/vrf-go + USERNAME: hacheigriega + PAT: ${{ secrets.PAT }} timeout-minutes: 10 steps: - uses: actions/setup-go@v4 with: go-version: "1.21" - uses: actions/checkout@v4 - - run: git config --global url.https://$GITHUB_TOKEN@github.com/.insteadOf https://github.com/ + - run: git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/ - uses: technote-space/get-diff-action@v6.0.1 with: PATTERNS: | **/**.go go.mod go.sum - - name: Build e2e Docker Image - run: make docker-build-e2e - - name: Test E2E - run: make test-e2e - + - name: Create .netrc file + run: | + echo "machine github.com" > ${GITHUB_WORKSPACE}/.netrc + echo " login ${USERNAME}" >> ${GITHUB_WORKSPACE}/.netrc + echo " password ${PAT}" >> ${GITHUB_WORKSPACE}/.netrc + chmod 600 ${GITHUB_WORKSPACE}/.netrc + - name: Test e2e + run: | + make test-e2e diff --git a/DEVELOPING.md b/DEVELOPING.md index 916bbc70..36473bce 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -160,7 +160,14 @@ To see test coverage: make cover-html ``` -To run end-to-end tests: +To run end-to-end tests, you first need to create a file `.netrc` containing GitHub credentials in the project root. This enables an access to the private repositories during the Docker build process. The `.netrc` file should look as follows: +```bash +machine github.com + login + password +``` + +The e2e testing can now be run with the following command: ```bash make test-e2e ``` diff --git a/app/app.go b/app/app.go index 22b78f2a..2ab9c4df 100644 --- a/app/app.go +++ b/app/app.go @@ -566,13 +566,11 @@ func NewApp( panic(fmt.Sprintf("error while reading wasm config: %s", err)) } - var wasmOpts []wasmkeeper.Option - randomnessQueryPlugin := keeper.NewQuerierImpl(app.RandomnessKeeper) queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ Custom: keeper.SeedQueryPlugin(randomnessQueryPlugin), }) - wasmOpts = append([]wasm.Option{queryPluginOpt}, wasmOpts...) + wasmOpts := []wasmkeeper.Option{queryPluginOpt} // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks diff --git a/dockerfiles/Dockerfile.e2e b/dockerfiles/Dockerfile.e2e index 7569252f..7dcacd80 100644 --- a/dockerfiles/Dockerfile.e2e +++ b/dockerfiles/Dockerfile.e2e @@ -18,15 +18,9 @@ RUN apk add --no-cache \ linux-headers \ git -# # Download go dependencies +# Download go dependencies COPY .netrc /root/ -# CMD echo $GITHUB_TOKEN - -# ENV GOPRIVATE=github.com/sedaprotocol/* -# ENV GIT_TERMINAL_PROMPT=0 - -# RUN git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" - +RUN chmod 600 /root/.netrc WORKDIR /seda-chain COPY go.mod go.sum ./ diff --git a/e2e/e2e_setup_test.go b/e2e/e2e_setup_test.go index 26d86604..6f10dc5a 100644 --- a/e2e/e2e_setup_test.go +++ b/e2e/e2e_setup_test.go @@ -12,14 +12,14 @@ import ( "testing" "time" - tmconfig "github.com/cometbft/cometbft/config" - tmjson "github.com/cometbft/cometbft/libs/json" - rpchttp "github.com/cometbft/cometbft/rpc/client/http" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/spf13/viper" "github.com/stretchr/testify/suite" + tmconfig "github.com/cometbft/cometbft/config" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + "cosmossdk.io/math" evidencetypes "cosmossdk.io/x/evidence/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -174,7 +175,7 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) { config.Moniker = validator.moniker genFilePath := config.GenesisFile() - appGenState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFilePath) + appGenState, appGenesis, err := genutiltypes.GenesisStateFromGenFile(genFilePath) s.Require().NoError(err) var evidenceGenState evidencetypes.GenesisState @@ -222,10 +223,15 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) { appGenState[genutiltypes.ModuleName], err = cdc.MarshalJSON(&genUtilGenState) s.Require().NoError(err) - genDoc.AppState, err = json.MarshalIndent(appGenState, "", " ") + appGenesis.AppState, err = json.MarshalIndent(appGenState, "", " ") + s.Require().NoError(err) + + genutil.ExportGenesisFile(appGenesis, genFilePath) + + err = appGenesis.ValidateAndComplete() s.Require().NoError(err) - bz, err := tmjson.MarshalIndent(genDoc, "", " ") + bz, err := json.MarshalIndent(appGenesis, "", " ") s.Require().NoError(err) // write the updated genesis file to each validator. diff --git a/e2e/genesis.go b/e2e/genesis.go index bf8f05d2..c3965ca9 100644 --- a/e2e/genesis.go +++ b/e2e/genesis.go @@ -7,14 +7,15 @@ import ( "cosmossdk.io/math" + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -46,6 +47,7 @@ func modifyGenesis(path, moniker, amountStr string, addrAll []sdk.AccAddress, gl return fmt.Errorf("failed to unmarshal genesis state: %w", err) } + // modify AppState authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState) accs, err := authtypes.UnpackAccounts(authGenState.Accounts) if err != nil { @@ -106,6 +108,8 @@ func modifyGenesis(path, moniker, amountStr string, addrAll []sdk.AccAddress, gl govparams := govv1.DefaultParams() votingPeriod := time.Duration(15) * time.Second govparams.VotingPeriod = &votingPeriod + expeditedVotingPeriod := time.Duration(10) * time.Second + govparams.ExpeditedVotingPeriod = &expeditedVotingPeriod govparams.MinDeposit = sdk.NewCoins(sdk.NewCoin(denom, math.NewInt(10000000))) govState := govv1.NewGenesisState(1, govparams) @@ -119,7 +123,21 @@ func modifyGenesis(path, moniker, amountStr string, addrAll []sdk.AccAddress, gl if err != nil { return fmt.Errorf("failed to marshal application genesis state: %w", err) } - genDoc.AppState = appStateJSON - return genutil.ExportGenesisFile(genDoc, genFile) + // modify CometBFT consensus genesis + consensusParams := cmttypes.DefaultConsensusParams() + consensusParams.Validator.PubKeyTypes = []string{"secp256k1"} + + // collect modified data and overwrite genesis file + appGenesis := &genutiltypes.AppGenesis{ + ChainID: genDoc.ChainID, + AppState: appStateJSON, + Consensus: &genutiltypes.ConsensusGenesis{ + Validators: nil, + Params: consensusParams, + }, + InitialHeight: int64(1), + } + + return genutil.ExportGenesisFile(appGenesis, genFile) } diff --git a/e2e/validator.go b/e2e/validator.go index d23bcb58..1175500f 100644 --- a/e2e/validator.go +++ b/e2e/validator.go @@ -9,6 +9,7 @@ import ( "path/filepath" tmcfg "github.com/cometbft/cometbft/config" + "github.com/cometbft/cometbft/crypto/secp256k1" tmos "github.com/cometbft/cometbft/libs/os" "github.com/cometbft/cometbft/p2p" "github.com/cometbft/cometbft/privval" @@ -73,7 +74,6 @@ func (v *validator) init() error { config.SetRoot(v.configDir()) config.Moniker = v.moniker - // TO-DO use existing genesis, if exists? appState, err := json.MarshalIndent(app.ModuleBasics.DefaultGenesis(cdc), "", " ") if err != nil { return fmt.Errorf("failed to JSON encode app genesis state: %w", err) @@ -123,7 +123,9 @@ func (v *validator) createConsensusKey() error { return err } - filePV := privval.LoadOrGenFilePV(pvKeyFile, pvStateFile) + filePV := privval.NewFilePV(secp256k1.GenPrivKey(), config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()) + filePV.Save() + v.consensusKey = filePV.Key return nil diff --git a/go.mod b/go.mod index 667cc6da..1d8d52da 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/hyperledger/burrow v0.34.4 github.com/ory/dockertest/v3 v3.10.0 github.com/pkg/errors v0.9.1 - github.com/sedaprotocol/vrf-go v0.0.0-20231202231847-9ca3f58655e6 + github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index e00c7027..7f6fa938 100644 --- a/go.sum +++ b/go.sum @@ -1096,6 +1096,10 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= github.com/sedaprotocol/vrf-go v0.0.0-20231202231847-9ca3f58655e6 h1:GqAxxdvT0bteI0b0Sq3iPDMP6BGlymYjPHCOveK9KH4= github.com/sedaprotocol/vrf-go v0.0.0-20231202231847-9ca3f58655e6/go.mod h1:cub/hpbOATCymOnKPJVOhuExFhhspWaOJW2nr/yzWUs= +github.com/sedaprotocol/vrf-go v0.0.0-20231211032335-c4a11d69429d h1:K3ttV/oBQlaO4grPIK9cy477HgiVHysMbsj94k4BQZc= +github.com/sedaprotocol/vrf-go v0.0.0-20231211032335-c4a11d69429d/go.mod h1:DEIXHk41VUzOMVbZnIApssPXtZ+2zrETDP7kJjGc1RM= +github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c h1:PbSn7HpWeox6lqBu6Ba6YZS3On3euwn1BPz/egsnEgA= +github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c/go.mod h1:DEIXHk41VUzOMVbZnIApssPXtZ+2zrETDP7kJjGc1RM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= diff --git a/scripts/local_setup.sh b/scripts/local_setup.sh index cdbc1277..158eb1eb 100755 --- a/scripts/local_setup.sh +++ b/scripts/local_setup.sh @@ -15,7 +15,7 @@ rm -rf ~/.seda-chain $BIN init new node0 cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="30s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json -cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="30s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json +# cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="30s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["expedited_voting_period"]="15s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json cat $HOME/.seda-chain/config/genesis.json | jq '.consensus["params"]["validator"]["pub_key_types"]=["secp256k1"]' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json diff --git a/x/randomness/keeper/abci.go b/x/randomness/keeper/abci.go index c9c6a9e6..6ea6f11c 100644 --- a/x/randomness/keeper/abci.go +++ b/x/randomness/keeper/abci.go @@ -55,25 +55,16 @@ func PrepareProposalHandler( } // produce VRF proof - k256vrf := vrf.NewK256VRF(0xFE) + k256vrf := vrf.NewK256VRF() pi, err := k256vrf.Prove(secretKey.Bytes(), alpha) if err != nil { return nil, err } - // debug - fmt.Println(alpha) - fmt.Println(secretKey.Bytes()) - fmt.Println(pi) - beta, err := k256vrf.ProofToHash(pi) if err != nil { return nil, err } - // // zero it out - // for i := range secretKey { - // secretKey[i] = 0 - // } validator, err := stakingKeeper.GetValidatorByConsAddr(ctx, sdk.ConsAddress(req.ProposerAddress)) if err != nil { @@ -152,7 +143,7 @@ func ProcessProposalHandler( } // verify VRF proof - k256vrf := vrf.NewK256VRF(0xFE) + k256vrf := vrf.NewK256VRF() beta, err := k256vrf.Verify(publicKey.Bytes(), pi, alpha) if err != nil { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err @@ -225,7 +216,6 @@ func encodeNewSeedTx(ctx sdk.Context, txConfig client.TxConfig, privKey crypto.P } sigBytes, err := privKey.Sign(bytesToSign) - // sigBytes, err := v.privateKey.Sign(bytesToSign) if err != nil { return nil, nil, err } diff --git a/x/staking/module.go b/x/staking/module.go index 7a0c8847..1259838c 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -32,7 +32,6 @@ func NewAppModule( ak AccountKeeper, bk stakingtypes.BankKeeper, ls exported.Subspace, - ) AppModule { am := staking.NewAppModule(cdc, keeper, ak, bk, ls) return AppModule{