@@ -10,7 +10,8 @@ import {
1010 MsgInitiateTx,
1111 MsgInitiateTxResponse,
1212 ContractTransaction,
13- Link
13+ Link,
14+ ReturnValue
1415} from "../src/proto/cross/core/initiator/Initiator.sol " ;
1516import {Account as AuthAccount, AuthType} from "../src/proto/cross/core/auth/Auth.sol " ;
1617import {Tx} from "../src/proto/cross/core/tx/Tx.sol " ;
@@ -82,51 +83,92 @@ contract TxManagerTest is Test {
8283 assertFalse (harness.exposed_isTxRecorded (txId), "Should return false for unrecorded tx " );
8384 }
8485
85- function test_createTx_SucceedsWithFullData () public {
86+ function test_createTx_SucceedsWithNonEmptyData () public {
8687 bytes32 deepCopyTxId = keccak256 ("deep_copy_tx " );
8788
89+ // --- 1. Setup mock data ---
8890 GoogleProtobufAny.Data memory emptyAny = GoogleProtobufAny.Data ({type_url: "" , value: "" });
8991 AuthType.Data memory localAuthType = AuthType.Data ({mode: AuthType.AuthMode.AUTH_MODE_LOCAL, option: emptyAny});
9092 AuthAccount.Data memory signerA = AuthAccount.Data ({id: bytes ("signerA " ), auth_type: localAuthType});
9193
94+ // --- 2. Build a complex calldata message with nested arrays ---
95+ // 2a. Top-level signers
9296 AuthAccount.Data[] memory signers_mem = new AuthAccount.Data [](1 );
9397 signers_mem[0 ] = signerA;
9498
99+ // 2b. Nested contract transactions
95100 ContractTransaction.Data[] memory txs_mem = new ContractTransaction.Data [](1 );
96101 Link.Data[] memory links_mem = new Link.Data [](1 );
97102 links_mem[0 ] = Link.Data ({src_index: 123 });
98103
99- txs_mem[0 ].signers = signers_mem;
100- txs_mem[0 ].links = links_mem;
104+ txs_mem[0 ].signers = signers_mem; // Nested signers
105+ txs_mem[0 ].links = links_mem; // Nested links
101106 txs_mem[0 ].call_info = hex "C0FFEE " ;
107+ txs_mem[0 ].cross_chain_channel = GoogleProtobufAny.Data ({type_url: "xcc_type " , value: hex "01 " });
108+ txs_mem[0 ].return_value = ReturnValue.Data ({value: bytes ("RETURNVAL " )});
102109
110+ // 2c. Main message
103111 MsgInitiateTx.Data memory nonEmptyTxMsg = MsgInitiateTx.Data ({
104112 chain_id: "test-chain-deep " ,
105- nonce: 2 ,
106- commit_protocol: Tx.CommitProtocol.COMMIT_PROTOCOL_SIMPLE ,
107- timeout_height: IbcCoreClientV1Height.Data (0 , 0 ),
108- timeout_timestamp: 0 ,
113+ nonce: 99 ,
114+ commit_protocol: Tx.CommitProtocol.COMMIT_PROTOCOL_TPC ,
115+ timeout_height: IbcCoreClientV1Height.Data (1 , 101 ),
116+ timeout_timestamp: 202 ,
109117 signers: signers_mem,
110118 contract_transactions: txs_mem
111119 });
112120
121+ // --- 3. Execute the function under test ---
113122 harness.exposed_createTx (deepCopyTxId, nonEmptyTxMsg);
114123
124+ // --- 4. Assert status (ensures coverage for non-empty paths) ---
115125 assertTrue (harness.exposed_isTxRecorded (deepCopyTxId), "Tx should be recorded " );
116126 assertEq (
117127 uint256 (harness.getTxStatus (deepCopyTxId)),
118128 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_PENDING),
119129 "Status should be PENDING "
120130 );
121131
132+ // --- 5. Verify deep copy by reading back from storage ---
122133 MsgInitiateTx.Data memory storedMsg = harness.exposed_getTxMsg (deepCopyTxId);
134+
135+ // 5a. Verify top-level simple fields
136+ assertEq (storedMsg.chain_id, "test-chain-deep " , "chain_id mismatch " );
137+ assertEq (storedMsg.nonce, 99 , "nonce mismatch " );
138+ assertEq (
139+ uint256 (storedMsg.commit_protocol),
140+ uint256 (Tx.CommitProtocol.COMMIT_PROTOCOL_TPC),
141+ "commit_protocol mismatch "
142+ );
143+ assertEq (storedMsg.timeout_height.version_number, 1 , "timeout_height.version_number mismatch " );
144+ assertEq (storedMsg.timeout_height.version_height, 101 , "timeout_height.version_height mismatch " );
145+ assertEq (storedMsg.timeout_timestamp, 202 , "timeout_timestamp mismatch " );
146+
147+ // 5b. Verify top-level signers array
123148 assertEq (storedMsg.signers.length , 1 , "Top signers length mismatch " );
124149 assertEq (storedMsg.signers[0 ].id, signerA.id, "Top signer id mismatch " );
150+ assertEq (
151+ uint256 (storedMsg.signers[0 ].auth_type.mode), uint256 (localAuthType.mode), "Top signer auth_type mismatch "
152+ );
153+
154+ // 5c. Verify contract_transactions array (level 1 nesting)
125155 assertEq (storedMsg.contract_transactions.length , 1 , "Txs length mismatch " );
126- assertEq (storedMsg.contract_transactions[0 ].call_info, hex "C0FFEE " , "Tx call_info mismatch " );
127- assertEq (storedMsg.contract_transactions[0 ].signers.length , 1 , "Nested signers length mismatch " );
128- assertEq (storedMsg.contract_transactions[0 ].links.length , 1 , "Links length mismatch " );
129- assertEq (storedMsg.contract_transactions[0 ].links[0 ].src_index, 123 , "Link src_index mismatch " );
156+ ContractTransaction.Data memory storedTx = storedMsg.contract_transactions[0 ];
157+ assertEq (storedTx.cross_chain_channel.type_url, "xcc_type " , "Tx xcc.type_url mismatch " );
158+ assertEq (storedTx.cross_chain_channel.value, hex "01 " , "Tx xcc.value mismatch " );
159+ assertEq (storedTx.call_info, hex "C0FFEE " , "Tx call_info mismatch " );
160+ assertEq (storedTx.return_value.value, bytes ("RETURNVAL " ), "Tx return_value mismatch " );
161+
162+ // 5d. Verify nested signers array (level 2 nesting)
163+ assertEq (storedTx.signers.length , 1 , "Nested signers length mismatch " );
164+ assertEq (storedTx.signers[0 ].id, signerA.id, "Nested signer id mismatch " );
165+ assertEq (
166+ uint256 (storedTx.signers[0 ].auth_type.mode), uint256 (localAuthType.mode), "Nested signer auth_type mismatch "
167+ );
168+
169+ // 5e. Verify nested links array (level 2 nesting)
170+ assertEq (storedTx.links.length , 1 , "Links length mismatch " );
171+ assertEq (storedTx.links[0 ].src_index, 123 , "Link src_index mismatch " );
130172 }
131173
132174 function test_createTx_RevertWhen_TxAlreadyExists () public {
0 commit comments