Skip to content

Commit

Permalink
fix: workflow fix and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Dec 13, 2023
1 parent 2d3c5e8 commit d6d5e1f
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 53 deletions.
37 changes: 23 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:

permissions:
contents: read
repository-projects: read
packages: read

concurrency:
group: ci-${{ github.ref }}-tests
Expand All @@ -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]
Expand Down Expand Up @@ -49,7 +51,9 @@ jobs:
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
- run: git config --global url.https://[email protected]/.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: |
Expand All @@ -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
Expand All @@ -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/[email protected]
id: git_diff
with:
Expand All @@ -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://[email protected]/.insteadOf https://github.com/
- run: git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/
- uses: technote-space/[email protected]
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
9 changes: 8 additions & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <YOUR_USERNAME>
password <YOUR_GITHUB_TOKEN>
```

The e2e testing can now be run with the following command:
```bash
make test-e2e
```
4 changes: 1 addition & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions dockerfiles/Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand Down
18 changes: 12 additions & 6 deletions e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ 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"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 22 additions & 4 deletions e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
6 changes: 4 additions & 2 deletions e2e/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion scripts/local_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 2 additions & 12 deletions x/randomness/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit d6d5e1f

Please sign in to comment.