Skip to content

Commit

Permalink
fix: fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Jun 18, 2024
1 parent 52973d4 commit f2b739d
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 94 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ seda.env

# coverage files
coverage.txt
/.run/debug existing.run.xml
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
go.uber.org/mock v0.4.0
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c
google.golang.org/grpc v1.63.2
Expand Down Expand Up @@ -208,8 +207,6 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
Expand Down
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1079,13 +1079,6 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
Expand Down
80 changes: 0 additions & 80 deletions x/wasm-storage/keeper/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"errors"

"github.com/tidwall/gjson"
)

const (
Expand All @@ -12,66 +10,6 @@ const (
filterStdDev byte = 0x02
)

type (
modeFilter struct {
Algo uint
JSONPath string
}

//stdFilter struct {
// Algo uint
// JSONPath string
// MaxSigma uint64
// NumberType uint8
//}
)

func FilterMode(jsonPath string, exitCodes []uint8, reveals [][]byte) ([]bool, bool) {
var (
outliers []bool
consensus bool
nonZeroExitCode int
)

vals := make([]string, 0, len(reveals))
for i, r := range reveals {
vals = append(vals, gjson.GetBytes(r, jsonPath).String())
if exitCodes[i] != 0 {
nonZeroExitCode++
}
}
outliers, consensus = calculate(vals)

if consensus || nonZeroExitCode*3 > 2*len(reveals) {
return outliers, true
}
return outliers, false
}

func calculate[T comparable](reveals []T) ([]bool, bool) {
freq := make(map[T]int, len(reveals))
outliers := make([]bool, 0, len(reveals))
var maxFreq int

for _, r := range reveals {
freq[r]++
if freq[r] > maxFreq {
maxFreq = freq[r]
}
}

if maxFreq*3 < len(reveals)*2 {
outliers = make([]bool, len(reveals))
return outliers, false
}

for _, r := range reveals {
outliers = append(outliers, freq[r] != maxFreq)
}

return outliers, true
}

// ApplyFilter processes filter of the type specified in the first byte of
// tally inputs. It returns an outlier list, which is a boolean list where
// true at index i means that the reveal at index i is an outlier, consensus
Expand All @@ -91,24 +29,6 @@ func ApplyFilter(tallyInputs []byte, reveals []RevealBody) ([]bool, bool, error)

case filterMode:
// TODO: Reactivate mode filter
/*
var filter modeFilter
if err := rlp.DecodeBytes(tallyInputs, &filter); err != nil {
return nil, false, err
}
if filter.JSONPath == "" {
return nil, false, errors.New("empty JSON path")
}
exitCodes := make([]uint8, len(reveals))
revealData := make([][]byte, len(reveals))
for i, r := range reveals {
exitCodes[i] = r.ExitCode
revealData[i] = r.Reveal
}
outliers, consensus := FilterMode(filter.JSONPath, exitCodes, revealData)
return outliers, consensus, nil
*/
return nil, false, errors.New("filter type mode is not implemented")

case filterStdDev:
Expand Down
6 changes: 4 additions & 2 deletions x/wasm-storage/keeper/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestOutliers_None(t *testing.T) {
}{
{
name: "None filter",
tallyInput: []byte{193, 128}, // filterProp{ Algo: 0}
tallyInput: []byte{0, 26, 129, 196}, // filterProp{ Algo: 0}
want: []bool{false, false, false, false, false},
reveals: []keeper.RevealBody{
{},
Expand All @@ -36,7 +36,9 @@ func TestOutliers_None(t *testing.T) {
require.ErrorIs(t, err, tt.wantErr)
return
}
require.Equal(t, got, tt.want)

require.NoError(t, err)
require.Equal(t, tt.want, got)
})
}
}
2 changes: 1 addition & 1 deletion x/wasm-storage/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *KeeperTestSuite) TestStoreOverlayWasm() {
{
name: "invalid authority",
input: types.MsgStoreOverlayWasm{
Sender: "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc",
Sender: "seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l",
Wasm: regWasmZipped,
WasmType: types.WasmTypeRelayer,
},
Expand Down

0 comments on commit f2b739d

Please sign in to comment.