Skip to content

Commit 605c68f

Browse files
committed
fixed predicate validation: wrong token was used
1 parent 667b299 commit 605c68f

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

tests/token/CommonTestFlow.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ export async function testTransferFlow(client: StateTransitionClient): Promise<v
6565
[new CoinId(crypto.getRandomValues(new Uint8Array(32))), BigInt(Math.round(Math.random() * 90)) + 10n],
6666
]),
6767
);
68-
const token = await mintToken(client, data);
68+
const aliceToken = await mintToken(client, data);
6969

7070
await expect(DirectAddress.create(data.predicate.reference)).resolves.toEqual(
71-
await DirectAddress.fromJSON(token.genesis.data.recipient),
71+
await DirectAddress.fromJSON(aliceToken.genesis.data.recipient),
7272
);
7373

7474
// Recipient (Bob) prepares the info for the transfer
7575
const bobNonce = crypto.getRandomValues(new Uint8Array(32));
7676
const bobSigningService = await SigningService.createFromSecret(bobSecret, bobNonce);
7777
const bobPredicate = await MaskedPredicate.create(
78-
token.id,
79-
token.type,
78+
aliceToken.id,
79+
aliceToken.type,
8080
bobSigningService,
8181
HashAlgorithm.SHA256,
8282
bobNonce,
@@ -85,13 +85,13 @@ export async function testTransferFlow(client: StateTransitionClient): Promise<v
8585
// Create transfer transaction
8686
const transaction = await sendToken(
8787
client,
88-
token,
88+
aliceToken,
8989
await SigningService.createFromSecret(initialOwnerSecret, data.nonce),
9090
await DirectAddress.create(bobPredicate.reference),
9191
);
9292

9393
// Recipient imports token
94-
const importedToken = await tokenFactory.create(token.toJSON());
94+
const importedToken = await tokenFactory.create(aliceToken.toJSON());
9595
// Recipient gets transaction from sender
9696
const importedTransaction = await transactionDeserializer.deserialize(
9797
importedToken.id,
@@ -100,51 +100,51 @@ export async function testTransferFlow(client: StateTransitionClient): Promise<v
100100
);
101101

102102
// Finish the transaction with the recipient predicate
103-
const updateToken = await client.finishTransaction(
103+
const bobToken = await client.finishTransaction(
104104
importedToken,
105105
await TokenState.create(bobPredicate, textEncoder.encode('my custom data')),
106106
importedTransaction,
107107
);
108108

109109
const minterSigningService = await SigningService.createFromSecret(
110110
initialOwnerSecret,
111-
token.state.unlockPredicate.nonce,
111+
aliceToken.state.unlockPredicate.nonce,
112112
);
113-
await expect(updateToken.state.unlockPredicate.isOwner(bobSigningService.publicKey)).resolves.toBeTruthy();
113+
await expect(bobToken.state.unlockPredicate.isOwner(bobSigningService.publicKey)).resolves.toBeTruthy();
114114
await expect(
115-
updateToken.transactions.at(-1)?.data.sourceState.unlockPredicate.isOwner(minterSigningService.publicKey),
115+
bobToken.transactions.at(-1)?.data.sourceState.unlockPredicate.isOwner(minterSigningService.publicKey),
116116
).resolves.toBeTruthy();
117-
expect(updateToken.id).toEqual(token.id);
118-
expect(updateToken.type).toEqual(token.type);
119-
expect(updateToken.data).toEqual(token.data);
120-
expect(updateToken.coins?.toJSON()).toEqual(token.coins?.toJSON());
117+
expect(bobToken.id).toEqual(aliceToken.id);
118+
expect(bobToken.type).toEqual(aliceToken.type);
119+
expect(bobToken.data).toEqual(aliceToken.data);
120+
expect(bobToken.coins?.toJSON()).toEqual(aliceToken.coins?.toJSON());
121121

122122
// Verify the original minted token has been spent
123123
const senderSigningService = await SigningService.createFromSecret(initialOwnerSecret, data.nonce);
124-
const mintedTokenStatus = await client.getTokenStatus(token, senderSigningService.publicKey);
124+
const mintedTokenStatus = await client.getTokenStatus(aliceToken, senderSigningService.publicKey);
125125
expect(mintedTokenStatus).toEqual(InclusionProofVerificationStatus.OK);
126126

127127
// Verify the updated token has not been spent
128-
const transferredTokenStatus = await client.getTokenStatus(updateToken, bobSigningService.publicKey);
128+
const transferredTokenStatus = await client.getTokenStatus(bobToken, bobSigningService.publicKey);
129129
expect(transferredTokenStatus).toEqual(InclusionProofVerificationStatus.PATH_NOT_INCLUDED);
130130

131131
// Transfer to the third owner (Carol) with UnmaskedPredicate
132132
const carolSecret = textEncoder.encode('Carol');
133133
const carolNonce = crypto.getRandomValues(new Uint8Array(32));
134134
const carolSigningService = await SigningService.createFromSecret(carolSecret, carolNonce);
135-
const carolRef = await UnmaskedPredicate.calculateReference(token.type, carolSigningService.algorithm, carolSigningService.publicKey, HashAlgorithm.SHA256);
135+
const carolRef = await UnmaskedPredicate.calculateReference(aliceToken.type, carolSigningService.algorithm, carolSigningService.publicKey, HashAlgorithm.SHA256);
136136
const carolAddress = await DirectAddress.create(carolRef);
137137

138138
// Create transfer transaction Bob -> Carol
139139
const txToCarol = await sendToken(
140140
client,
141-
token,
141+
bobToken,
142142
bobSigningService,
143143
carolAddress,
144144
);
145145

146146
// Carol imports token
147-
const carolToken = await tokenFactory.create(updateToken.toJSON());
147+
const carolToken = await tokenFactory.create(bobToken.toJSON());
148148
// Carol gets transaction from Bob
149149
const carolTransaction = await transactionDeserializer.deserialize(
150150
carolToken.id,

0 commit comments

Comments
 (0)