@@ -9,11 +9,13 @@ import "../src/core/TxManagerBase.sol";
99import {
1010 MsgInitiateTx,
1111 MsgInitiateTxResponse,
12- ContractTransaction
12+ ContractTransaction,
13+ Link
1314} from "../src/proto/cross/core/initiator/Initiator.sol " ;
14- import {Account as AuthAccount} from "../src/proto/cross/core/auth/Auth.sol " ;
15+ import {Account as AuthAccount, AuthType } from "../src/proto/cross/core/auth/Auth.sol " ;
1516import {Tx} from "../src/proto/cross/core/tx/Tx.sol " ;
1617import {IbcCoreClientV1Height} from "../src/proto/ibc/core/client/v1/client.sol " ;
18+ import {GoogleProtobufAny} from "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol " ;
1719
1820contract MockTxRunner is TxRunner {
1921 uint256 public runCount;
@@ -42,6 +44,11 @@ contract TxManagerHarness is TxManager, MockTxRunner {
4244 CoreStore.TxStorage storage t = _getTxStorage ();
4345 return t.txStatus[txId];
4446 }
47+
48+ function exposed_getTxMsg (bytes32 txId ) public view returns (MsgInitiateTx.Data memory ) {
49+ CoreStore.TxStorage storage t = _getTxStorage ();
50+ return t.txMsg[txId];
51+ }
4552}
4653
4754contract TxManagerTest is Test {
@@ -68,46 +75,76 @@ contract TxManagerTest is Test {
6875
6976 function test_isTxRecorded_ReturnsTrueForKnownTx () public {
7077 harness.exposed_createTx (txId, txMsg);
71-
7278 assertTrue (harness.exposed_isTxRecorded (txId), "Should return true for recorded tx " );
7379 }
7480
7581 function test_isTxRecorded_ReturnsFalseForUnknownTx () public view {
7682 assertFalse (harness.exposed_isTxRecorded (txId), "Should return false for unrecorded tx " );
7783 }
7884
79- function test_createTx_SucceedsAndSetsPendingStatus () public {
80- harness.exposed_createTx (txId, txMsg);
85+ function test_createTx_SucceedsWithFullData () public {
86+ bytes32 deepCopyTxId = keccak256 ("deep_copy_tx " );
87+
88+ GoogleProtobufAny.Data memory emptyAny = GoogleProtobufAny.Data ({type_url: "" , value: "" });
89+ AuthType.Data memory localAuthType = AuthType.Data ({mode: AuthType.AuthMode.AUTH_MODE_LOCAL, option: emptyAny});
90+ AuthAccount.Data memory signerA = AuthAccount.Data ({id: bytes ("signerA " ), auth_type: localAuthType});
91+
92+ AuthAccount.Data[] memory signers_mem = new AuthAccount.Data [](1 );
93+ signers_mem[0 ] = signerA;
94+
95+ ContractTransaction.Data[] memory txs_mem = new ContractTransaction.Data [](1 );
96+ Link.Data[] memory links_mem = new Link.Data [](1 );
97+ links_mem[0 ] = Link.Data ({src_index: 123 });
98+
99+ txs_mem[0 ].signers = signers_mem;
100+ txs_mem[0 ].links = links_mem;
101+ txs_mem[0 ].call_info = hex "C0FFEE " ;
102+
103+ MsgInitiateTx.Data memory nonEmptyTxMsg = MsgInitiateTx.Data ({
104+ 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 ,
109+ signers: signers_mem,
110+ contract_transactions: txs_mem
111+ });
112+
113+ harness.exposed_createTx (deepCopyTxId, nonEmptyTxMsg);
81114
82- assertTrue (harness.exposed_isTxRecorded (txId ), "Tx should be recorded " );
115+ assertTrue (harness.exposed_isTxRecorded (deepCopyTxId ), "Tx should be recorded " );
83116 assertEq (
84- uint256 (harness.getTxStatus (txId )),
117+ uint256 (harness.getTxStatus (deepCopyTxId )),
85118 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_PENDING),
86119 "Status should be PENDING "
87120 );
121+
122+ MsgInitiateTx.Data memory storedMsg = harness.exposed_getTxMsg (deepCopyTxId);
123+ assertEq (storedMsg.signers.length , 1 , "Top signers length mismatch " );
124+ assertEq (storedMsg.signers[0 ].id, signerA.id, "Top signer id mismatch " );
125+ 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 " );
88130 }
89131
90132 function test_createTx_RevertWhen_TxAlreadyExists () public {
91133 harness.exposed_createTx (txId, txMsg); // First time
92-
93134 vm.expectRevert (abi.encodeWithSelector (TxManagerBase.TxAlreadyExists.selector , txId));
94135 harness.exposed_createTx (txId, txMsg); // Second time
95136 }
96137
97138 function test_runTxIfCompleted_RunsTxAndSetsVerifiedStatus () public {
98139 harness.exposed_createTx (txId, txMsg);
99-
100140 assertEq (
101141 uint256 (harness.getTxStatus (txId)),
102142 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_PENDING),
103143 "Status should be PENDING "
104144 );
105-
106145 harness.exposed_runTxIfCompleted (txId);
107-
108146 assertEq (harness.runCount (), 1 , "MockTxRunner should be called once " );
109147 assertEq (harness.lastRunTxId (), txId, "MockTxRunner should be called with correct txId " );
110-
111148 assertEq (
112149 uint256 (harness.getTxStatus (txId)),
113150 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED),
@@ -122,19 +159,15 @@ contract TxManagerTest is Test {
122159
123160 function test_runTxIfCompleted_DoesNothingIfAlreadyVerified () public {
124161 harness.exposed_createTx (txId, txMsg);
125-
126- harness.exposed_runTxIfCompleted (txId); // First run, runCount = 1
162+ harness.exposed_runTxIfCompleted (txId); // First run
127163 assertEq (harness.runCount (), 1 , "MockTxRunner should be called once " );
128-
129164 assertEq (
130165 uint256 (harness.getTxStatus (txId)),
131166 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED),
132167 "Status should be VERIFIED "
133168 );
134-
135- harness.exposed_runTxIfCompleted (txId); // Second run, should do nothing
169+ harness.exposed_runTxIfCompleted (txId); // Second run
136170 assertEq (harness.runCount (), 1 , "MockTxRunner should not be called again " );
137-
138171 assertEq (
139172 uint256 (harness.getTxStatus (txId)),
140173 uint256 (MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED),
0 commit comments