@@ -15,6 +15,45 @@ import (
1515 "github.com/stretchr/testify/require"
1616)
1717
18+ func TestCreateIntentSubdigestLeaves_Valid (t * testing.T ) {
19+ // Create a valid transaction (stx) with required fields.
20+ stx := & sequence.Transaction {
21+ DelegateCall : false ,
22+ RevertOnError : true ,
23+ Nonce : big .NewInt (0 ),
24+ // other required fields for stx (if any) are assumed to be set.
25+ }
26+
27+ // Use the valid transaction in a slice.
28+ txns := []* sequence.Transaction {stx }
29+
30+ leaves , err := sequence .CreateIntentSubdigestLeaves (txns )
31+ require .NoError (t , err )
32+ require .Len (t , leaves , 1 , "expected one subdigest leaf" )
33+
34+ // Verify that the leaf's digest matches the transaction's digest.
35+ digest , err := stx .Digest ()
36+ require .NoError (t , err )
37+ require .Equal (t , digest , leaves [0 ].Subdigest .Hash , "digests do not match" )
38+ }
39+
40+ func TestCreateIntentConfiguration_Valid (t * testing.T ) {
41+ // Create a valid transaction.
42+ stx := & sequence.Transaction {
43+ DelegateCall : false ,
44+ RevertOnError : true ,
45+ Nonce : big .NewInt (0 ),
46+ }
47+ txns := []* sequence.Transaction {stx }
48+
49+ // Use a valid main signer address.
50+ mainSigner := common .HexToAddress ("0x1111111111111111111111111111111111111111" )
51+
52+ config , err := sequence .CreateIntentConfiguration (mainSigner , txns )
53+ require .NoError (t , err )
54+ require .NotNil (t , config )
55+ }
56+
1857func TestCreateIntentConfigurationSignature (t * testing.T ) {
1958 // Create test wallets
2059 eoa1 , err := ethwallet .NewWalletFromRandomEntropy ()
@@ -26,8 +65,10 @@ func TestCreateIntentConfigurationSignature(t *testing.T) {
2665 assert .NoError (t , err )
2766
2867 stx := & sequence.Transaction {
29- To : callmockContract .Address ,
30- Data : calldata ,
68+ To : callmockContract .Address ,
69+ Data : calldata ,
70+ RevertOnError : true ,
71+ Nonce : big .NewInt (0 ),
3172 }
3273
3374 t .Run ("signature matches subdigest" , func (t * testing.T ) {
@@ -96,13 +137,17 @@ func TestCreateIntentConfigurationSignature(t *testing.T) {
96137 require .NoError (t , err )
97138
98139 tx1 := & sequence.Transaction {
99- To : callmockContract .Address ,
100- Data : calldata1 ,
140+ To : callmockContract .Address ,
141+ Data : calldata1 ,
142+ RevertOnError : true ,
143+ Nonce : big .NewInt (0 ),
101144 }
102145
103146 tx2 := & sequence.Transaction {
104- To : callmockContract .Address ,
105- Data : calldata2 ,
147+ To : callmockContract .Address ,
148+ Data : calldata2 ,
149+ RevertOnError : true ,
150+ Nonce : big .NewInt (0 ),
106151 }
107152
108153 // Create signatures for both transactions
@@ -128,3 +173,42 @@ func TestCreateIntentConfigurationSignature(t *testing.T) {
128173 require .Equal (t , sig1 , sig2 , "same transactions should produce same signatures" )
129174 })
130175}
176+
177+ func TestCreateIntentConfigurationSignature_MultipleTransactions (t * testing.T ) {
178+ // Create test wallets
179+ eoa1 , err := ethwallet .NewWalletFromRandomEntropy ()
180+ require .NoError (t , err )
181+
182+ // Create two valid transactions with different Data fields so their digests differ.
183+ stx1 := & sequence.Transaction {
184+ DelegateCall : false ,
185+ RevertOnError : true ,
186+ Nonce : big .NewInt (0 ),
187+ Data : []byte ("transaction1" ),
188+ }
189+ stx2 := & sequence.Transaction {
190+ DelegateCall : false ,
191+ RevertOnError : true ,
192+ Nonce : big .NewInt (0 ),
193+ Data : []byte ("transaction2" ),
194+ }
195+ txns := []* sequence.Transaction {stx1 , stx2 }
196+
197+ // Create a signature
198+ sig , err := sequence .CreateIntentConfigurationSignature (eoa1 .Address (), txns )
199+ require .NoError (t , err )
200+
201+ // Convert the full signature into a hex string.
202+ sigHex := common .Bytes2Hex (sig )
203+
204+ // Create the bundle from the transactions
205+ bundle , err := sequence .CreateIntentBundle (txns )
206+ require .NoError (t , err )
207+
208+ // Compute the digest of the bundle
209+ bundleDigest , err := bundle .Digest ()
210+ require .NoError (t , err )
211+
212+ // Expect that the signature (in hex) contains the substrings of both transactions' digests.
213+ assert .Contains (t , sigHex , bundleDigest .Hex ()[2 :], "signature should contain stx1 digest" )
214+ }
0 commit comments