Skip to content

Commit 52216f6

Browse files
committed
tests: using wrong constant in partial_tx
1 parent df22b85 commit 52216f6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

__tests__/storage/memory_store.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,11 @@ test('history methods', async () => {
161161
test('token methods', async () => {
162162
const store = new MemoryStore();
163163

164-
// Starts with HTR
165-
expect(store.tokens.size).toEqual(1);
166-
expect(store.tokens.get('00')).toBeDefined();
164+
// Starts empty
165+
expect(store.tokens.size).toEqual(0);
167166

168167
await store.saveToken({ uid: '01', name: 'Token 01', symbol: 'TK01' });
169-
expect(store.tokens.size).toEqual(2);
168+
expect(store.tokens.size).toEqual(1);
170169
expect(store.tokens.get('01')).toBeDefined();
171170
expect(store.tokensMetadata.get('01')).toBeUndefined();
172171
await store.saveToken(
@@ -182,7 +181,7 @@ test('token methods', async () => {
182181
},
183182
}
184183
);
185-
expect(store.tokens.size).toEqual(3);
184+
expect(store.tokens.size).toEqual(2);
186185
expect(store.tokens.get('02')).toBeDefined();
187186
expect(store.tokensMetadata.get('02')).toBeDefined();
188187

@@ -208,6 +207,7 @@ test('token methods', async () => {
208207
}
209208
expect(registered).toHaveLength(1);
210209

210+
await store.saveToken({ uid: '00', name: 'Hathor', symbol: 'HTR' });
211211
await store.editTokenMeta('00', {
212212
numTransactions: 10,
213213
balance: { tokens: { locked: 1, unlocked: 2 } },

src/models/partial_tx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import txApi from '../api/txApi';
2323
import {
2424
DEFAULT_TX_VERSION,
2525
NATIVE_TOKEN_UID,
26+
TOKEN_INDEX_MASK,
2627
TOKEN_AUTHORITY_MASK,
2728
TOKEN_MELT_MASK,
2829
TOKEN_MINT_MASK,
@@ -484,7 +485,7 @@ export class PartialTx {
484485
const tokenUid =
485486
utxo.token_data === 0
486487
? NATIVE_TOKEN_UID
487-
: get(data, `tx.tokens[${(utxo.token_data & TOKEN_AUTHORITY_MASK) - 1}].uid`);
488+
: get(data, `tx.tokens[${(utxo.token_data & TOKEN_INDEX_MASK) - 1}].uid`);
488489

489490
const isAuthority = (utxo.token_data & TOKEN_AUTHORITY_MASK) > 0;
490491
const isMint = isAuthority && (utxo.value & TOKEN_MINT_MASK) > 0;

src/utils/storage.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import walletApi from '../api/wallet';
2424
import helpers from './helpers';
2525
import transactionUtils from './transaction';
2626
import { deriveAddressP2PKH, deriveAddressP2SH } from './address';
27-
import { MAX_ADDRESSES_GET, LOAD_WALLET_MAX_RETRY, LOAD_WALLET_RETRY_SLEEP } from '../constants';
27+
import { NATIVE_TOKEN_UID, MAX_ADDRESSES_GET, LOAD_WALLET_MAX_RETRY, LOAD_WALLET_RETRY_SLEEP } from '../constants';
2828

2929
/**
3030
* Derive requested addresses (if not already loaded), save them on storage then return them.
@@ -403,6 +403,15 @@ async function updateTokensData(storage: IStorage, tokens: Set<string>): Promise
403403
> {
404404
let retryCount = 0;
405405

406+
if (uid === NATIVE_TOKEN_UID) {
407+
const nativeToken = storage.config.getNativeTokenData();
408+
return {
409+
success: true,
410+
name: nativeToken.name,
411+
symbol: nativeToken.symbol,
412+
};
413+
}
414+
406415
while (retryCount <= 5) {
407416
try {
408417
// Fetch and return the api response

0 commit comments

Comments
 (0)