feat(sc-13): implement merchant registration with MerchantMetadata struct#78
Conversation
…ruct - Add MerchantMetadata struct with name, business_type, contact_info fields - Update register_merchant(admin, merchant, metadata) signature per issue spec - Add InvalidMetadata error variant for field length validation - Update MerchantRegistered event to emit full MerchantMetadata payload - Add 12 tests: registration flow, metadata persistence, validation errors, duplicate prevention, admin-only access, activation/deactivation, count tracking Closes TrustUp-app#68
|
Hey Diego, do you need fix the CIs before to merge |
Josue19-08NC
left a comment
There was a problem hiding this comment.
Good work overall — the PR description is clear and well-organized, the struct decomposition makes sense, and the test coverage is solid. However there are issues that need to be addressed before this can merge.
CI: Test Contracts is failing
The 'Test Contracts' CI check failed (Build Contracts passed). The PR cannot be merged while tests are failing in CI. Please investigate and fix the failing tests — the locally-passing claim in the description contradicts the CI result.
Missing lower-bound validation on business_type and contact_info
In lib.rs, the name field correctly rejects empty strings (len == 0), but business_type and contact_info only enforce an upper bound:
if metadata.business_type.len() > 64 {
return Err(Error::InvalidMetadata);
}
if metadata.contact_info.len() > 128 {
return Err(Error::InvalidMetadata);
}If both fields are intentionally optional (empty string allowed), that must be documented explicitly in the doc comment and in the PR description. If they are required fields, add a lower-bound check (len == 0) for both, just like name. Right now the intent is ambiguous and the behavior is inconsistent.
No test for empty business_type or contact_info
There is no test that explicitly covers the empty-string case for business_type or contact_info. Whether these should be rejected or accepted, add a test that pins the intended behavior.
Error naming inconsistency
InvalidName (code 5) handles name validation, while InvalidMetadata (code 7) handles business_type and contact_info. Since business_type and contact_info are part of MerchantMetadata and name is also a field of MerchantMetadata, this split is confusing. Consider either renaming InvalidName to something that makes the distinction clearer, or consolidating both under a single error variant with a message. At minimum, the doc comment on the error variants should explain which fields each one covers.
Minor: internal alias is unnecessary
In lib.rs:
use types::{MerchantInfo, MerchantMetadata as MerchantMeta};MerchantMeta is used only in the register_merchant signature. Since MerchantMetadata is already publicly re-exported, just import it directly without the alias to avoid confusion for readers.
Summary of required changes
- Fix the failing CI test suite.
- Clarify and enforce (or document) the lower-bound behavior for business_type and contact_info.
- Add tests that cover the empty-string case for those two fields.
- Clarify the error variant naming or add doc comments explaining which fields map to which error.
Josue19-08
left a comment
There was a problem hiding this comment.
Good work overall — the PR description is clear, well-organized, and covers the changes thoroughly. The struct decomposition for MerchantMetadata is a clean improvement over the bare name field, and the test suite is comprehensive. However, there are issues that must be resolved before this can merge.
Blocking: CI test suite is failing
The 'Test Contracts' check failed (Build Contracts passed). The PR cannot merge while CI tests are red. The description claims tests pass locally — please investigate the discrepancy and push a fix.
Missing lower-bound validation on business_type and contact_info
In lib.rs, name correctly rejects empty strings, but business_type and contact_info only enforce an upper bound:
if metadata.business_type.len() > 64 { return Err(Error::InvalidMetadata); }
if metadata.contact_info.len() > 128 { return Err(Error::InvalidMetadata); }
This means empty strings are silently accepted for both fields. If they are optional, document that explicitly in the doc comment on the struct fields and in the PR description. If they are required, add a len() == 0 check for each, consistent with how name is handled.
No test pinning empty-string behavior for business_type / contact_info
Whether empty is accepted or rejected, add a test that explicitly covers the empty-string case for both fields. Right now the intended behavior is undocumented and untested.
Unnecessary internal type alias
In lib.rs:
use types::{MerchantInfo, MerchantMetadata as MerchantMeta};
MerchantMeta is only used in the register_merchant signature. MerchantMetadata is already the public name and is re-exported directly below. Remove the alias and import MerchantMetadata directly to avoid confusion for readers.
Error variant naming inconsistency
InvalidName (code 5) covers the name field inside MerchantMetadata, while InvalidMetadata (code 7) covers the other two fields of the same struct. The split is confusing since all three are metadata fields. Consider either renaming InvalidName to make the distinction clearer, or adding doc comments to each error variant explicitly listing which fields each one covers.
Required changes before merge
- Fix the failing CI test suite.
- Clarify and enforce (or document) lower-bound behavior for business_type and contact_info.
- Add tests covering the empty-string case for those two fields.
- Remove the MerchantMeta alias; import MerchantMetadata directly.
- Add doc comments to InvalidName and InvalidMetadata clarifying which fields each variant covers.
Josue19-08
left a comment
There was a problem hiding this comment.
This PR still has the same issues flagged in the previous two reviews (June 25). No new commits have been pushed since June 19, and CI 'Test Contracts' remains failing. The PR cannot merge in this state.
Blocking: CI test suite is still failing
The 'Test Contracts' check has been failing since the first CI run. No fix has been pushed. The PR must have a green CI run before it can be merged.
Still unresolved from previous reviews
- Missing lower-bound validation for business_type and contact_info — empty strings are silently accepted. Either reject them (add len() == 0 check consistent with how name is validated) or explicitly document and test that they are optional.
- No tests covering the empty-string case for business_type or contact_info. Whatever behavior is intended must be pinned by a test.
- Unnecessary type alias in lib.rs:
use types::{MerchantInfo, MerchantMetadata as MerchantMeta}. MerchantMeta is only used in the register_merchant signature. Import MerchantMetadata directly. - Error variant naming: InvalidName (code 5) and InvalidMetadata (code 7) both validate fields inside MerchantMetadata. Add doc comments to each variant listing which fields it covers, or consolidate.
Please fix the CI failure first, then address the remaining items, and re-request review.
Description
Implements SC-13: Merchant Registration for the
merchant-registry-contract, aligning the contract with the issue specification.The key change is updating
register_merchantto accept aMerchantMetadatastruct instead of a barename: String, enabling richer merchant data to be stored and emitted on-chain.Type of Change
Changes Made
types.rs— AddedMerchantMetadata { name, business_type, contact_info }struct;MerchantInfonow embedsmetadata: MerchantMetadatainstead of a barenamefieldlib.rs— Updatedregister_merchant(admin, merchant, metadata)signature per issue spec; added validation for all metadata fields; documented error variantserrors.rs— AddedInvalidMetadata = 7error variant forbusiness_type/contact_infolength validationevents.rs—MerchantRegisteredevent now emits fullMerchantMetadatapayload instead of just a name stringTesting
New tests added (12 total):
test_registration_flow— full happy path with metadata fieldstest_metadata_stored_correctly— verifies all 3 metadata fields persist correctlytest_invalid_name_empty— rejects empty nametest_invalid_name_too_long— rejects name > 64 charstest_invalid_business_type_too_long— rejects business_type > 64 charstest_invalid_contact_info_too_long— rejects contact_info > 128 charstest_merchant_count_increments— verifies count tracking across multiple registrationsChecklist
Closes #68