Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev o ref2 test #6

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5b90181
use base64 of hash to emit nst-balance-change-event, don't reset inde…
leonz789 Dec 26, 2024
4be11e9
don't slash on oracle downtime
leonz789 Dec 27, 2024
cf16231
use lowercase to compare nst prefix
leonz789 Dec 27, 2024
cc24754
fix: update roundID in staker's balance list
leonz789 Dec 27, 2024
edcb46b
ref:feedermanager. todo:events, uts, aggregator-tally
leonz789 Jan 6, 2025
1d24d79
remove unused file
leonz789 Jan 6, 2025
b7df2b5
fix:pepareround,logs. complete:round tally related functions,state co…
leonz789 Jan 8, 2025
b08083f
feat: add recovery check in beginblock for devmode-build
leonz789 Jan 9, 2025
6fed352
feat: update snapshot of feedermanager as state for checkTx mode
leonz789 Jan 9, 2025
e3006b3
emit events in endblock for updated feeders
leonz789 Jan 9, 2025
d49bf96
revert changes to GrowRoundID
leonz789 Jan 9, 2025
e17ab7d
add unit tests for aggregation
leonz789 Jan 9, 2025
9b45e9f
add equal methods for recovery logic check
leonz789 Jan 9, 2025
1e11dc3
remove outdated aggregator
leonz789 Jan 10, 2025
ae71654
add build tag devmode and corresponding beginblock for recovery check
leonz789 Jan 12, 2025
d8a5b20
fix lint
leonz789 Jan 13, 2025
b3cc497
fix lint
leonz789 Jan 13, 2025
78cba6f
revert localnodesh
leonz789 Jan 13, 2025
867aa4b
fix checking for overflow
leonz789 Jan 13, 2025
a0af70b
move e2e out of ut-cover test from ci
leonz789 Jan 13, 2025
5cc31d2
separate job
leonz789 Jan 13, 2025
2e7bf74
separate test jobs
leonz789 Jan 13, 2025
9f25460
fix map iteration, ref
leonz789 Jan 13, 2025
13ce46d
print log instead of panic in endBlock
leonz789 Jan 13, 2025
93a0287
Merge branch 'develop-oracle-refactor2.0' into dev-o-ref2-test
leonz789 Jan 13, 2025
f581b7a
logs, set algo for aggregator
leonz789 Jan 13, 2025
3fcb5ac
fix set newround with AggAlgorithm
leonz789 Jan 13, 2025
345604e
fix
leonz789 Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ jobs:
run: |
make test-unit-cover
if: env.GIT_DIFF
test-unit-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.21'
check-latest: true
- uses: actions/checkout@v4
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Test e2e cases
run: |
make test-unit-e2e
if: env.GIT_DIFF
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ all: build

build-all: tools build lint test vulncheck

.PHONY: distclean clean build-all
.PHONY: distclean clean build-all build

###############################################################################
### makTools & Dependencies ###
Expand Down Expand Up @@ -305,23 +305,27 @@ test-all: test-unit test-race
# we want to include all unit tests in the subfolders (tests/e2e/*)
# We also want to exclude the testutil folder because it contains only
# helper functions for the tests.
PACKAGES_UNIT=$(shell go list ./... | grep -v '/tests/e2e$$' | grep -v 'testutil')
PACKAGES_UNIT=$(shell go list ./... | grep -v '/tests/e2e' | grep -v 'testutil')
PACKAGES_UNIT_E2E=$(shell go list ./... | grep '/tests/e2e')
TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-unit-cover test-race
TEST_TARGETS := test-unit test-unit-cover test-race test-unit-e2e

# Test runs-specific rules. To add a new test target, just add
# a new rule, customise ARGS or TEST_PACKAGES ad libitum, and
# append the new rule to the TEST_TARGETS list.
test-unit: ARGS=-timeout=15m -gcflags=all=-l
test-unit: ARGS=-timeout=15m -gcflags=all=-l --tags devmode
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)

test-race: ARGS=-race
test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION)
$(TEST_TARGETS): run-tests

test-unit-cover: ARGS=-timeout=15m -coverprofile=cover.out -covermode=atomic -gcflags=all=-l
test-unit-cover: ARGS=-timeout=15m -coverprofile=cover.out -covermode=atomic -gcflags=all=-l --tags devmode
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)

test-unit-e2e: ARGS=-timeout=15m --tags devmode
test-unit-e2e: TEST_PACKAGES=$(PACKAGES_UNIT_E2E)

test-e2e:
@if [ -z "$(TARGET_VERSION)" ]; then \
echo "Building docker image from local codebase"; \
Expand Down Expand Up @@ -634,4 +638,4 @@ check-licenses:
@python3 scripts/check_licenses.py .

swagger-ui:
docker run -p 8080:8080 -e SWAGGER_JSON=/app/swagger.json -v $(pwd)/client/docs/swagger-ui:/app swaggerapi/swagger-ui
docker run -p 8080:8080 -e SWAGGER_JSON=/app/swagger.json -v $(pwd)/client/docs/swagger-ui:/app swaggerapi/swagger-ui
3 changes: 3 additions & 0 deletions app/ante/cosmos/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
msg := msg.(*oracletypes.MsgCreatePrice)
if accAddress, err := sdk.AccAddressFromBech32(msg.Creator); err != nil {
return ctx, errors.New("invalid address")
// #nosec G115 // safe conversion
// TODO: define msg.Nonce as uint32 to avoid conversion
} else if _, err := isd.oracleKeeper.CheckAndIncreaseNonce(ctx, sdk.ConsAddress(accAddress).String(), msg.FeederID, uint32(msg.Nonce)); err != nil {
return ctx, err
}
Expand Down Expand Up @@ -445,6 +447,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
sigCount := 0
for _, pk := range pubKeys {
sigCount += CountSubKeys(pk)
// #nosec G115
if uint64(sigCount) > params.TxSigLimit {
return ctx, sdkerrors.ErrTooManySignatures.Wrapf("signatures: %d, limit: %d", sigCount, params.TxSigLimit)
}
Expand Down
2 changes: 2 additions & 0 deletions app/ante/cosmos/txsize_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
}

// use stdsignature to mock the size of a full signature
// #nosec G115
simSig := legacytx.StdSignature{ // nolint:staticcheck // this will be removed when proto is ready
Signature: simSecp256k1Sig[:],
PubKey: pubkey,
}

sigBz := legacy.Cdc.MustMarshal(simSig)
// #nosec G115
cost := sdk.Gas(len(sigBz) + 6)

// If the pubkey is a multi-signature pubkey, then we estimate for the maximum
Expand Down
18 changes: 9 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,15 @@ func NewExocoreApp(
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, // to upgrade the chain
capabilitytypes.ModuleName, // before any module with capabilities like IBC
epochstypes.ModuleName, // to update the epoch
feemarkettypes.ModuleName, // set EIP-1559 gas prices
evmtypes.ModuleName, // stores chain id in memory
slashingtypes.ModuleName, // TODO after reward
evidencetypes.ModuleName, // TODO after reward
stakingtypes.ModuleName, // track historical info
ibcexported.ModuleName, // handles upgrades of chain and hence client
authz.ModuleName, // clear expired approvals
oracleTypes.ModuleName,
epochstypes.ModuleName, // to update the epoch
feemarkettypes.ModuleName, // set EIP-1559 gas prices
evmtypes.ModuleName, // stores chain id in memory
slashingtypes.ModuleName, // TODO after reward
evidencetypes.ModuleName, // TODO after reward
stakingtypes.ModuleName, // track historical info
ibcexported.ModuleName, // handles upgrades of chain and hence client
authz.ModuleName, // clear expired approvals
// no-op modules
ibctransfertypes.ModuleName,
icatypes.ModuleName,
Expand All @@ -943,7 +944,6 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
oracleTypes.ModuleName,
distrtypes.ModuleName,
)

Expand Down
2 changes: 2 additions & 0 deletions precompiles/avs/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (p Precompile) EmitTaskSubmittedByOperator(ctx sdk.Context, stateDB vm.Stat
}
// Prepare the event data:sender,TaskResponse, BlsSignature, Phase
arguments := abi.Arguments{event.Inputs[2], event.Inputs[3], event.Inputs[4], event.Inputs[5]}
// #nosec G115
// TODO: consider modify define of Phase to uint8
packed, err := arguments.Pack(params.CallerAddress.String(), params.TaskResponse, params.BlsSignature, uint8(params.Phase))
if err != nil {
return err
Expand Down
33 changes: 24 additions & 9 deletions tests/e2e/oracle/create_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ func (s *E2ETestSuite) testCreatePriceLST() {
// query final price
res, err := s.network.QueryOracle().LatestPrice(context.Background(), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
s.Require().Equal(priceTest1R1.getPriceTimeRound(1), res.Price)
// NOTE: update timestamp manually to ignore
ret := priceTest1R1.getPriceTimeRound(1)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)

// TODO: there might be a small chance that the blockHeight grows to more than 13, try bigger price window(nonce>3) to be more confident
// send create-price from validator3 to avoid being slashed for downtime
Expand Down Expand Up @@ -134,8 +137,10 @@ func (s *E2ETestSuite) testCreatePriceLST() {
res, err = s.network.QueryOracle().LatestPrice(context.Background(), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
// price update fail, round 2 still have price{p1}
s.Require().Equal(priceTest1R1.getPriceTimeRound(2), res.Price)

// NOTE: update timestamp manually to ignore
ret = priceTest1R1.getPriceTimeRound(2)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)
// case_3. slashing_{miss_v3:2, window:3} [1.0.1]
// update timestamp
priceTest2R3 := price2.updateTimestamp()
Expand Down Expand Up @@ -167,7 +172,10 @@ func (s *E2ETestSuite) testCreatePriceLST() {
res, err = s.network.QueryOracle().LatestPrice(context.Background(), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
// price updated, round 3 has price{p2}
s.Require().Equal(priceTest2R3.getPriceTimeRound(3), res.Price)
// NOTE: update timestamp manually to ignore
ret = priceTest2R3.getPriceTimeRound(3)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)

// case_4. slashing_{miss_v3:2, window:4}.maxWindow=4 [1.0.1.0]
// update timestamp
Expand All @@ -186,7 +194,10 @@ func (s *E2ETestSuite) testCreatePriceLST() {
res, err = s.network.QueryOracle().LatestPrice(context.Background(), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
// price updated, round 4 has price{p1}
s.Require().Equal(priceTest1R4.getPriceTimeRound(4), res.Price)
// NOTE: update timestamp manually to ignore
ret = priceTest1R4.getPriceTimeRound(4)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)
// send create-price from validator3 to avoid being slashed for downtime
msg3 = oracletypes.NewMsgCreatePrice(creator3.String(), 1, []*oracletypes.PriceSource{&priceSource1R4}, 40, 1)
err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg3}, "valconskey3", kr3)
Expand Down Expand Up @@ -266,11 +277,13 @@ func (s *E2ETestSuite) testCreatePriceNST() {
s.Require().Equal([]*oracletypes.BalanceInfo{
{
Block: 6,
Index: 0,
Balance: 32,
Change: oracletypes.Action_ACTION_DEPOSIT,
},
{
RoundID: 1,
Index: 1,
Block: 8,
Balance: 28,
Change: oracletypes.Action_ACTION_SLASH_REFUND,
Expand Down Expand Up @@ -299,7 +312,10 @@ func (s *E2ETestSuite) testSlashing() {
res, err := s.network.QueryOracle().LatestPrice(context.Background(), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
// price updated, round 4 has price{p1}
s.Require().Equal(priceTest1R5.getPriceTimeRound(5), res.Price)
// NOTE: update timestamp manually to ignore
ret := priceTest1R5.getPriceTimeRound(5)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)
s.moveToAndCheck(60)
// slashing_{miss_v3:3, window:5} [0.1.0.1.1] -> {miss_v3:2, window:4} [1.0.1.1]
_, priceSource1R6 := price1.generateRealTimeStructs("14", 1)
Expand All @@ -312,7 +328,7 @@ func (s *E2ETestSuite) testSlashing() {
s.Require().NoError(err)
err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg2}, "valconskey2", kr2)
s.Require().NoError(err)
s.moveToAndCheck(63)
s.moveToAndCheck(64)
resSigningInfo, err := s.network.QuerySlashing().SigningInfo(context.Background(), &slashingtypes.QuerySigningInfoRequest{ConsAddress: sdk.ConsAddress(s.network.Validators[3].PubKey.Address()).String()})
s.Require().NoError(err)
// validator3 is jailed
Expand All @@ -331,7 +347,6 @@ func (s *E2ETestSuite) testSlashing() {
s.moveNAndCheck(2)
resOperator, err = s.network.QueryOperator().QueryOptInfo(context.Background(), &operatortypes.QueryOptInfoRequest{OperatorAVSAddress: &operatortypes.OperatorAVSAddress{OperatorAddr: s.network.Validators[3].Address.String(), AvsAddress: avsAddr}})
s.Require().NoError(err)
fmt.Println("debug----->jailed:", resOperator.Jailed)
s.Require().False(resOperator.Jailed)
}

Expand All @@ -353,7 +368,7 @@ func (s *E2ETestSuite) testRegisterTokenThroughPrecompile() {
// registerToken will automaticlly register that token into oracle module
res, err := s.network.QueryOracle().Params(context.Background(), &oracletypes.QueryParamsRequest{})
s.Require().NoError(err)
s.Require().Equal(name, res.Params.Tokens[3].Name)
s.Require().Equal(name, res.Params.Tokens[len(res.Params.Tokens)-1].Name)
}

func (s *E2ETestSuite) moveToAndCheck(height int64) {
Expand Down
9 changes: 7 additions & 2 deletions tests/e2e/oracle/helper_nstconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oracle

import (
"encoding/binary"
"math"
"strings"

"github.com/imroc/biu"
Expand All @@ -10,8 +11,7 @@ import (
func convertBalanceChangeToBytes(stakerChanges [][]int) []byte {
if len(stakerChanges) == 0 {
// length equals to 0 means that alls takers have efb of 32 with 0 changes
ret := make([]byte, 32)
return ret
return make([]byte, 32)
}
str := ""
index := 0
Expand All @@ -23,6 +23,10 @@ func convertBalanceChangeToBytes(stakerChanges [][]int) []byte {

// change amount -> bytes
change := stakerChange[1]
if (change > 0 && change > math.MaxUint16) ||
(change < 0 && (-1*change) > math.MaxUint16) {
return make([]byte, 32)
}
var changeBytes []byte
symbol := 1
if change < 0 {
Expand All @@ -47,6 +51,7 @@ func convertBalanceChangeToBytes(stakerChanges [][]int) []byte {
} else {
// 2 byte
changeBytes = make([]byte, 2)
// #nosec G115 // change has been checked to make sure no overflow
binary.BigEndian.PutUint16(changeBytes, uint16(change))
moveLength := 16 - bits
changeBytes[0] <<= moveLength
Expand Down
1 change: 1 addition & 0 deletions testutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func (suite *BaseTestSuite) DoSetupTest() {
queryHelperEvm := baseapp.NewQueryServerTestHelper(suite.Ctx, suite.App.InterfaceRegistry())
evmtypes.RegisterQueryServer(queryHelperEvm, suite.App.EvmKeeper)
suite.QueryClientEVM = evmtypes.NewQueryClient(queryHelperEvm)
suite.App.OracleKeeper.FeederManager.BeginBlock(suite.Ctx)
}

// DeployContract deploys a contract that calls the deposit precompile's methods for testing purposes.
Expand Down
2 changes: 1 addition & 1 deletion x/avs/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func newBuildMsg(
taskContractAddress, _ := fs.GetString(FlagTaskContractAddress)

taskID, _ := fs.GetUint64(FlagTaskID)
phase, _ := fs.GetUint32(FlagPhase)
phase, _ := fs.GetInt32(FlagPhase)
if err := types.ValidatePhase(types.Phase(phase)); err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,14 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *types.Challeng
return errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s",
avsInfo.EpochIdentifier))
}
// #nosec G115
if epoch.CurrentEpoch <= int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod) {
return errorsmod.Wrap(
types.ErrSubmitTooSoonError,
fmt.Sprintf("SetTaskResultInfo:the challenge period has not started , CurrentEpoch:%d", epoch.CurrentEpoch),
)
}
// #nosec G115
if epoch.CurrentEpoch > int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod)+int64(taskInfo.TaskChallengePeriod) {
return errorsmod.Wrap(
types.ErrSubmitTooLateError,
Expand Down Expand Up @@ -589,6 +591,7 @@ func (k Keeper) SubmitTaskResult(ctx sdk.Context, addr string, info *types.TaskR
fmt.Sprintf("SetTaskResultInfo:the TaskResponse period has not started , CurrentEpoch:%d", epoch.CurrentEpoch),
)
}
// #nosec G115
if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod)+int64(task.TaskStatisticalPeriod) {
return errorsmod.Wrap(
types.ErrSubmitTooLateError,
Expand Down
2 changes: 2 additions & 0 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ
continue
}
txConfig.TxHash = ethTx.Hash()
// #nosec G115
txConfig.TxIndex = uint(i)
// reset gas meter for each transaction
ctx = ctx.WithGasMeter(evmostypes.NewInfiniteGasMeterWithLimit(msg.Gas()))
Expand Down Expand Up @@ -565,6 +566,7 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
result := types.TxTraceResult{}
ethTx := tx.AsTransaction()
txConfig.TxHash = ethTx.Hash()
// #nosec G115
txConfig.TxIndex = uint(i)
traceResult, logIndex, err := k.traceTx(ctx, cfg, txConfig, signer, ethTx, req.TraceConfig, true, nil)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/operator/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// GetSlashIDForDogfood It use infractionType+'_'+'infractionHeight' as the slashID, because /* the slash */event occurs in dogfood doesn't have a TxID. It isn't submitted through an external transaction.
func GetSlashIDForDogfood(infraction stakingtypes.Infraction, infractionHeight int64) string {
// #nosec G701
// #nosec G115
return strings.Join([]string{hexutil.EncodeUint64(uint64(infraction)), hexutil.EncodeUint64(uint64(infractionHeight))}, utils.DelimiterForID)
}

Expand Down
2 changes: 1 addition & 1 deletion x/operator/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func KeyForVotingPowerSnapshot(avs common.Address, height int64) []byte {
return utils.AppendMany(
avs.Bytes(),
// Append the height
sdk.Uint64ToBigEndian(uint64(height)),
sdk.Uint64ToBigEndian(uint64(height)), // #nosec G115 // height is not negative
)
}

Expand Down
Loading
Loading