Skip to content

feat: Testing with automated crosschain validation framework #10

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

Open
wants to merge 2 commits into
base: poc/deploy-nmsc-gasless
Choose a base branch
from

Conversation

mohammeds1992
Copy link

No description provided.

@mohammeds1992 mohammeds1992 requested review from 0xNilesh and Aman035 May 23, 2025 09:32
@mohammeds1992 mohammeds1992 changed the title Testing with automated crosschain validation framework feat: Testing with automated crosschain validation framework May 23, 2025
Copy link
Member

@0xNilesh 0xNilesh left a comment

Choose a reason for hiding this comment

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

Test cases are missing for message handlers
Main application logic test cases are not implemented

expectError: true,
errorContains: "unauthorized",
},
// BUG 1: Invalid hex characters accepted
Copy link
Member

Choose a reason for hiding this comment

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

In this test file, the UpdateAdminParams function is being tested through the message handler.

In Cosmos SDK transactions, there are three main phases after a transaction is created:

  1. CheckTx – The SDK calls the ValidateBasic() method of each message. Stateless checks are performed here, and the transaction is rejected if any validation fails.
  2. DeliverTx – Ante handlers are executed first, followed by the message handlers (MsgServer). This phase handles stateful logic.
  3. Commit – State changes from DeliverTx are committed to the application state.

Because input validation is handled by ValidateBasic() during the CheckTx phase, it does not need to be repeated in the message handler (MsgServer). Therefore, testing input validations in the message handler tests is not appropriate.
Ideally, input validation should be tested in unit tests for the ValidateBasic() method, not in the message handler tests.

},
// BUG 2: Empty factory address accepted
{
name: "bug 2: empty factory address accepted",
Copy link
Member

Choose a reason for hiding this comment

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

invalid due to above reason

"github.com/rollchains/pchain/x/crosschain/types"
)

func TestUpdateAdminParams(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

tests for msg handlers should not include stateless validation tests

Instead, these should be focused on stateful logic and application behaviour
e.g. correct state transitions, access control, any interaction with other keepers, or any extra functionality that's implemented

name: "control characters",
factoryAddr: "0x527F3692F5C53\nCfA83F7689885995606F93b6164",
expectError: true,
errorMessage: "contains control characters",
Copy link
Member

Choose a reason for hiding this comment

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

In the Cosmos SDK, ValidateBasic() should be cheap and fast, it's intended for lightweight, stateless checks that ensure the message is syntactically valid before any expensive processing happens.

We shouldn't add these specific error messages and validation just for validating a address
a standard "invalid factory address" error msg or a similar one should be fine for address check fails

errorMessage: "invalid address",
},
{
name: "zero address",
Copy link
Member

Choose a reason for hiding this comment

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

This is an admin controlled field, that's why didn't add a zero address check considering admin is always trusted
But this additional check could be added.
Will add this

txHash: "0x123",
expectError: false, // Should this be validated? Worth testing
},
{
Copy link
Member

Choose a reason for hiding this comment

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

don't know if all VMs have txHash in a hex format, need to check

expectError: false, // Should this be validated? Worth testing
},
{
name: "namespace with special characters",
Copy link
Member

Choose a reason for hiding this comment

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

don't think should add that much validations
its supposed to be a cheap stateless validation
and if someone sends invalid characters, it anyway will revert in the msg execution when it'll be used for tx verification

expectError: false, // Should special chars be allowed in namespace? Worth testing
},
{
name: "chain id with special characters",
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't add this extensive checks

expectError: false, // Should value limits be validated? Worth testing
},
{
name: "deadline in the past",
Copy link
Member

Choose a reason for hiding this comment

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

doesn't matter, it'd revert in the smart contract

expectError: false, // Should nonce zero be allowed? Worth testing
},
{
name: "maxPriorityFeePerGas higher than maxFeePerGas",
Copy link
Member

Choose a reason for hiding this comment

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

again, should only check if payload parameters are valid
like target is a valid evm address
string fields are not empty, etc.
rest if someone sends invalid values in parameters, those will error out automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants