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

test(abci): Expand test coverage for WriteMessage and ReadMessage #1579

Open
wants to merge 2 commits into
base: v0.34.x-celestia
Choose a base branch
from
Open
Changes from all commits
Commits
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
171 changes: 161 additions & 10 deletions abci/types/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,95 @@ func TestWriteReadMessage(t *testing.T) {
Height: 4,
ChainID: "test",
},
// TODO: add the rest
// Expanded test cases covering various ABCI message types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what motivated this change? Did you see a GH issue that mentioned increasing test coverage here?

AFAIK these methods and types are consistent with upstream CometBFT v0.46.x so this change can instead target upstream and then we can pull it here.

Ref: https://github.com/celestiaorg/celestia-core?tab=readme-ov-file#contributing

&RequestCheckTx{
Tx: []byte("transaction data"),
Type: CheckTxType_New,
},
&ResponseCheckTx{
Code: 1,
Data: []byte("response data"),
GasWanted: 1000,
GasUsed: 500,
Events: []Event{
{
Type: "test_event",
Attributes: []EventAttribute{
{Key: []byte("key1"), Value: []byte("value1")},
{Key: []byte("key2"), Value: []byte("value2")},
},
},
},
},
&RequestDeliverTx{
Tx: []byte("deliver transaction"),
},
&ResponseDeliverTx{
Code: 0,
Data: []byte("delivery successful"),
GasWanted: 2000,
GasUsed: 1500,
},
&RequestBeginBlock{
Hash: []byte("block hash"),
Header: cmtproto.Header{
Height: 100,
ChainID: "test-chain",
},
LastCommitInfo: LastCommitInfo{
Round: 0,
Votes: []VoteInfo{
{
Validator: Validator{
Address: []byte("validator address"),
Power: 1000,
},
SignedLastBlock: true,
},
},
},
},
&ResponseBeginBlock{
Events: []Event{
{
Type: "block_begin",
Attributes: []EventAttribute{
{Key: []byte("block"), Value: []byte("started")},
},
},
},
},
&RequestEndBlock{
Height: 150,
},
&ResponseEndBlock{
ValidatorUpdates: []ValidatorUpdate{
{
Power: 500,
},
},
Events: []Event{
{
Type: "block_end",
Attributes: []EventAttribute{
{Key: []byte("block"), Value: []byte("completed")},
},
},
},
},
}

for _, c := range cases {
buf := new(bytes.Buffer)
err := WriteMessage(c, buf)
assert.Nil(t, err)
assert.Nil(t, err, "Failed to write message of type %T", c)

msg := new(cmtproto.Header)
// Create a new message of the same type to read into
msg := proto.Clone(c)
err = ReadMessage(buf, msg)
assert.Nil(t, err)
assert.Nil(t, err, "Failed to read message of type %T", c)

assert.True(t, proto.Equal(c, msg))
assert.True(t, proto.Equal(c, msg), "Message of type %T not equal after write and read", c)
}
}

Expand All @@ -97,18 +173,93 @@ func TestWriteReadMessage2(t *testing.T) {
},
},
},
// TODO: add the rest
&RequestDeliverTx{
Tx: []byte("transaction payload"),
},
&ResponseDeliverTx{
Code: 0,
Data: []byte("delivery successful"),
Log: "Transaction processed",
GasWanted: 100,
GasUsed: 50,
Events: []Event{
{
Type: "transfer",
Attributes: []EventAttribute{
{Key: []byte("recipient"), Value: []byte("address1")},
{Key: []byte("amount"), Value: []byte("1000")},
},
},
},
},
&RequestBeginBlock{
Hash: []byte("block-hash"),
Header: cmtproto.Header{
Height: 1000,
ChainID: "celestia-testnet",
},
LastCommitInfo: LastCommitInfo{
Round: 0,
Votes: []VoteInfo{
{
Validator: Validator{
Address: []byte("validator-address"),
Power: 1000,
},
SignedLastBlock: true,
},
},
},
},
&ResponseBeginBlock{
Events: []Event{
{
Type: "block_begin",
Attributes: []EventAttribute{
{Key: []byte("block_height"), Value: []byte("1000")},
{Key: []byte("proposer"), Value: []byte("validator-address")},
},
},
},
},
&RequestEndBlock{
Height: 1001,
},
&ResponseEndBlock{
ValidatorUpdates: []ValidatorUpdate{
{
Power: 1200,
},
},
ConsensusParamUpdates: nil,
Events: []Event{
{
Type: "block_end",
Attributes: []EventAttribute{
{Key: []byte("block_height"), Value: []byte("1001")},
{Key: []byte("status"), Value: []byte("completed")},
},
},
},
},
&RequestEcho{
Message: "ping",
},
&ResponseEcho{
Message: "pong",
},
}

for _, c := range cases {
buf := new(bytes.Buffer)
err := WriteMessage(c, buf)
assert.Nil(t, err)
assert.Nil(t, err, "Failed to write message of type %T", c)

msg := new(ResponseCheckTx)
// Create a new message of the same type to read into
msg := proto.Clone(c)
err = ReadMessage(buf, msg)
assert.Nil(t, err)
assert.Nil(t, err, "Failed to read message of type %T", c)

assert.True(t, proto.Equal(c, msg))
assert.True(t, proto.Equal(c, msg), "Message of type %T not equal after write and read", c)
}
}
Loading