2424import com .unicity .sdk .token .TokenState ;
2525import com .unicity .sdk .token .TokenType ;
2626import com .unicity .sdk .token .fungible .CoinId ;
27+ import com .unicity .sdk .transaction .MintTransactionReason ;
2728import com .unicity .sdk .transaction .split .SplitMintReason ;
2829import com .unicity .sdk .token .fungible .TokenCoinData ;
2930import com .unicity .sdk .transaction .InclusionProof ;
4849/**
4950 * Common test flows for token operations, matching TypeScript SDK's CommonTestFlow.
5051 */
51- @ SuppressWarnings ({"unchecked" , "rawtypes" })
5252public class CommonTestFlow {
5353
5454 private static final byte [] ALICE_SECRET = "Alice" .getBytes (StandardCharsets .UTF_8 );
@@ -76,8 +76,8 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
7676 Address aliceAddress = alicePredicate .getReference (tokenType ).toAddress ();
7777 TokenState aliceTokenState = new TokenState (alicePredicate , null );
7878
79- MintCommitment <? > aliceMintCommitment = MintCommitment .create (
80- new MintTransactionData (
79+ MintCommitment <MintTransactionData < MintTransactionReason > > aliceMintCommitment = MintCommitment .create (
80+ new MintTransactionData <> (
8181 tokenId ,
8282 tokenType ,
8383 new TestTokenData (randomBytes (32 )).getData (),
@@ -104,13 +104,49 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
104104 ).get ();
105105
106106 // Create mint transaction
107- Token aliceToken = new Token (
107+ Token <?> aliceToken = new Token <> (
108108 aliceTokenState ,
109109 aliceMintCommitment .toTransaction (mintInclusionProof )
110110 );
111111
112112 assertTrue (aliceToken .verify ().isSuccessful ());
113113
114+ String bobNameTag = UUID .randomUUID ().toString ();
115+
116+ // Alice transfers to Bob
117+ String bobCustomData = "Bob's custom data" ;
118+ byte [] bobStateData = bobCustomData .getBytes (StandardCharsets .UTF_8 );
119+ DataHash bobDataHash = new DataHasher (HashAlgorithm .SHA256 ).update (bobStateData ).digest ();
120+
121+ // Submit transfer transaction
122+ TransferCommitment aliceToBobTransferCommitment = TransferCommitment .create (
123+ aliceToken ,
124+ ProxyAddress .create (bobNameTag ),
125+ randomBytes (32 ),
126+ bobDataHash ,
127+ null ,
128+ aliceSigningService
129+ );
130+ SubmitCommitmentResponse aliceToBobTransferSubmitResponse = client .submitCommitment (aliceToken ,
131+ aliceToBobTransferCommitment ).get ();
132+
133+ if (aliceToBobTransferSubmitResponse .getStatus () != SubmitCommitmentStatus .SUCCESS ) {
134+ throw new Exception (String .format ("Failed to submit transaction commitment: %s" ,
135+ aliceToBobTransferSubmitResponse .getStatus ()));
136+ }
137+
138+ // Wait for inclusion proof
139+ InclusionProof aliceToBobTransferInclusionProof = InclusionProofUtils .waitInclusionProof (
140+ client ,
141+ aliceToBobTransferCommitment
142+ ).get ();
143+
144+ // Create transfer transaction
145+ Transaction <TransferTransactionData > aliceToBobTransferTransaction = aliceToBobTransferCommitment .toTransaction (
146+ aliceToken ,
147+ aliceToBobTransferInclusionProof
148+ );
149+
114150 // Bob prepares to receive the token
115151 byte [] bobNonce = randomBytes (32 );
116152 SigningService bobSigningService = SigningService .createFromSecret (BOB_SECRET , bobNonce );
@@ -119,6 +155,7 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
119155 DirectAddress bobAddress = bobPredicate .getReference (tokenType ).toAddress ();
120156
121157 // Bob mints a name tag tokens
158+
122159 byte [] bobNametagNonce = randomBytes (32 );
123160 MaskedPredicate bobNametagPredicate = MaskedPredicate .create (
124161 SigningService .createFromSecret (BOB_SECRET , bobNametagNonce ),
@@ -129,15 +166,16 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
129166 DirectAddress bobNametagAddress = bobNametagPredicate .getReference (bobNametagTokenType )
130167 .toAddress ();
131168 MintCommitment <?> nametagMintCommitment = MintCommitment .create (
132- MintTransactionData .createNametag (
133- UUID . randomUUID (). toString () ,
169+ MintTransactionData .createForNametag (
170+ bobNameTag ,
134171 bobNametagTokenType ,
135172 new byte [10 ],
136173 null ,
137174 bobNametagAddress ,
138175 randomBytes (32 ),
139176 bobAddress
140177 ));
178+
141179 SubmitCommitmentResponse nametagMintResponse = client .submitCommitment (nametagMintCommitment )
142180 .get ();
143181 if (nametagMintResponse .getStatus () != SubmitCommitmentStatus .SUCCESS ) {
@@ -151,47 +189,13 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
151189 nametagMintCommitment
152190 ).get ()
153191 );
154- Token <?> bobNametagToken = new Token (
192+ Token <?> bobNametagToken = new Token <> (
155193 new NameTagTokenState (bobNametagPredicate , bobAddress ),
156194 bobNametagGenesis
157195 );
158196
159- // Alice transfers to Bob
160- String bobCustomData = "Bob's custom data" ;
161- byte [] bobStateData = bobCustomData .getBytes (StandardCharsets .UTF_8 );
162- DataHash bobDataHash = new DataHasher (HashAlgorithm .SHA256 ).update (bobStateData ).digest ();
163-
164- // Submit transfer transaction
165- TransferCommitment aliceToBobTransferCommitment = TransferCommitment .create (
166- aliceToken ,
167- ProxyAddress .create (bobNametagGenesis .getData ().getTokenId ()),
168- randomBytes (32 ),
169- bobDataHash ,
170- null ,
171- aliceSigningService
172- );
173- SubmitCommitmentResponse aliceToBobTransferSubmitResponse = client .submitCommitment (aliceToken ,
174- aliceToBobTransferCommitment ).get ();
175-
176- if (aliceToBobTransferSubmitResponse .getStatus () != SubmitCommitmentStatus .SUCCESS ) {
177- throw new Exception (String .format ("Failed to submit transaction commitment: %s" ,
178- aliceToBobTransferSubmitResponse .getStatus ()));
179- }
180-
181- // Wait for inclusion proof
182- InclusionProof aliceToBobTransferInclusionProof = InclusionProofUtils .waitInclusionProof (
183- client ,
184- aliceToBobTransferCommitment
185- ).get ();
186-
187- // Create transfer transaction
188- Transaction <TransferTransactionData > aliceToBobTransferTransaction = aliceToBobTransferCommitment .toTransaction (
189- aliceToken ,
190- aliceToBobTransferInclusionProof
191- );
192-
193197 // Bob finalizes the token
194- Token bobToken = client .finalizeTransaction (
198+ Token <?> bobToken = client .finalizeTransaction (
195199 aliceToken ,
196200 new TokenState (bobPredicate , bobStateData ),
197201 aliceToBobTransferTransaction ,
@@ -246,7 +250,7 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
246250 carolNonce
247251 );
248252
249- Token carolToken = client .finalizeTransaction (
253+ Token <?> carolToken = client .finalizeTransaction (
250254 bobToken ,
251255 new TokenState (carolPredicate , null ),
252256 bobToCarolTransaction
@@ -410,7 +414,7 @@ public static void testTransferFlow(StateTransitionClient client) throws Excepti
410414 );
411415
412416 Assertions .assertTrue (
413- new Token (
417+ new Token <> (
414418 new TokenState (splitTokenPredicate , null ),
415419 splitTransactions .get (0 )
416420 ).verify ().isSuccessful ()
0 commit comments