Skip to content

Commit

Permalink
chore(systemtest): More stable fraud test (#21949)
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe authored Sep 27, 2024
1 parent dc09671 commit dcf00cf
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions tests/systemtests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

func TestValidatorDoubleSign(t *testing.T) {
Expand All @@ -27,43 +25,38 @@ func TestValidatorDoubleSign(t *testing.T) {
// Check the validator is in the active set
rsp := cli.CustomQuery("q", "staking", "validators")
t.Log(rsp)
nodePowerBefore := QueryCometValidatorPowerForNode(t, sut, 0)
validatorPubKey := LoadValidatorPubKeyForNode(t, sut, 0)
rpc, pkBz := sut.RPCClient(t), validatorPubKey.Bytes()

nodePowerBefore := QueryCometValidatorPower(rpc, pkBz)
require.NotEmpty(t, nodePowerBefore)
t.Logf("nodePowerBefore: %v", nodePowerBefore)

var validatorPubKey cryptotypes.PubKey
newNode := sut.AddFullnode(t, func(nodeNumber int, nodePath string) {
valKeyFile := filepath.Join(WorkDir, nodePath, "config", "priv_validator_key.json")
_ = os.Remove(valKeyFile)
_, err := copyFile(filepath.Join(WorkDir, sut.nodePath(0), "config", "priv_validator_key.json"), valKeyFile)
require.NoError(t, err)
validatorPubKey = LoadValidatorPubKeyForNode(t, sut, nodeNumber)
})
sut.AwaitNodeUp(t, fmt.Sprintf("http://%s:%d", newNode.IP, newNode.RPCPort))

// let's wait some blocks to have evidence and update persisted
rpc := sut.RPCClient(t)
pkBz := validatorPubKey.Bytes()
for i := 0; i < 20; i++ {
var nodePowerAfter int64 = -1
for i := 0; i < 30; i++ {
sut.AwaitNextBlock(t)
if QueryCometValidatorPower(rpc, pkBz) == 0 {
if nodePowerAfter = QueryCometValidatorPower(rpc, pkBz); nodePowerAfter == 0 {
break
}
t.Logf("wait %d", sut.CurrentHeight())
}
sut.AwaitNextBlock(t)

// then comet status updated
nodePowerAfter := QueryCometValidatorPowerForNode(t, sut, 0)
require.Empty(t, nodePowerAfter)
t.Logf("nodePowerAfter: %v", nodePowerAfter)

// and sdk status updated
byzantineOperatorAddr := cli.GetKeyAddrPrefix("node0", "val")
rsp = cli.CustomQuery("q", "staking", "validator", byzantineOperatorAddr)
assert.True(t, gjson.Get(rsp, "validator.jailed").Bool(), rsp)

t.Log("let's run for some blocks to confirm all good")
for i := 0; i < 10; i++ {
sut.AwaitNextBlock(t)
}
// let's run for some blocks to confirm all good
sut.AwaitNBlocks(t, 5)
}

0 comments on commit dcf00cf

Please sign in to comment.