Skip to content

Commit 845f510

Browse files
committed
chore: review changes
1 parent 853b229 commit 845f510

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

__tests__/integration/nanocontracts/bet.test.ts

-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe('full cycle of bet nano contract', () => {
9595

9696
// Create NC
9797
const oracleData = getOracleBuffer(address1, network);
98-
console.debug('Call to initialize');
9998
const tx1 = await wallet.createAndSendNanoContractTransaction(
10099
NANO_CONTRACTS_INITIALIZE_METHOD,
101100
address0,
@@ -178,7 +177,6 @@ describe('full cycle of bet nano contract', () => {
178177
).rejects.toThrow(NanoContractTransactionError);
179178

180179
// Bet 100 to address 2
181-
console.debug('First call to bet');
182180
const txBet = await wallet.createAndSendNanoContractTransaction('bet', address2, {
183181
ncId: tx1.hash,
184182
args: [address2, '1x0'],
@@ -234,7 +232,6 @@ describe('full cycle of bet nano contract', () => {
234232

235233
// Bet 200 to address 3
236234
const address3 = await wallet.getAddressAtIndex(3);
237-
console.debug('Second call to bet');
238235
const txBet2 = await wallet.createAndSendNanoContractTransaction('bet', address3, {
239236
ncId: tx1.hash,
240237
args: [address3, '2x0'],
@@ -328,7 +325,6 @@ describe('full cycle of bet nano contract', () => {
328325
const result = '1x0';
329326
const resultSerialized = nanoSerializer.serializeFromType(result, 'str');
330327
const inputData = await getOracleInputData(oracleData, tx1.hash, resultSerialized, wallet);
331-
console.debug('Call to set_result');
332328
const txSetResult = await wallet.createAndSendNanoContractTransaction('set_result', address1, {
333329
ncId: tx1.hash,
334330
args: [`${bufferToHex(inputData)},${result},str`],
@@ -369,7 +365,6 @@ describe('full cycle of bet nano contract', () => {
369365
expect((txSetResultParser.parsedArgs[0].value as NanoContractSignedData).value).toEqual(result);
370366

371367
// Try to withdraw to address 2, success
372-
console.debug('Call to withdraw');
373368
const txWithdrawal = await wallet.createAndSendNanoContractTransaction('withdraw', address2, {
374369
ncId: tx1.hash,
375370
actions: [

src/nano_contracts/methodArg.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
BufferROExtract,
1515
NanoContractArgumentApiInputType,
1616
NanoContractArgumentApiInputSchema,
17+
NanoContractArgumentByteTypes,
1718
} from './types';
1819
import Serializer from './serializer';
1920
import Deserializer from './deserializer';
@@ -52,9 +53,7 @@ function refineSingleValue(
5253
} else {
5354
return parse.data;
5455
}
55-
} else if (
56-
['bytes', 'BlueprintId', 'ContractId', 'TokenUid', 'TxOutputScript', 'VertexId'].includes(type)
57-
) {
56+
} else if (NanoContractArgumentByteTypes.safeParse(type).success) {
5857
const parse = z
5958
.string()
6059
.regex(/^[0-9A-Fa-f]+$/)
@@ -130,7 +129,7 @@ function refineSingleValue(
130129

131130
/**
132131
* Type and value validation for non-container types.
133-
* Returns the internal TS type for the argument given.
132+
* Returns the internal parsed value for the argument given.
134133
*/
135134
const SingleValueApiInputScheme = z
136135
.tuple([
@@ -262,11 +261,7 @@ export class NanoContractMethodArgument {
262261
if (type === 'bool') {
263262
return (value as boolean) ? 'true' : 'false';
264263
}
265-
if (
266-
['bytes', 'BlueprintId', 'ContractId', 'TokenUid', 'TxOutputScript', 'VertexId'].includes(
267-
type
268-
)
269-
) {
264+
if (NanoContractArgumentByteTypes.safeParse(type).success) {
270265
return (value as Buffer).toString('hex');
271266
}
272267
if (type === 'VarInt') {

src/nano_contracts/types.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,26 @@ export const NanoContractArgumentSchema = z.union([
5959
]);
6060
export type NanoContractArgumentType = z.output<typeof NanoContractArgumentSchema>;
6161

62+
export const NanoContractArgumentByteTypes = z.enum([
63+
'bytes',
64+
'Address',
65+
'BlueprintId',
66+
'ContractId',
67+
'TokenUid',
68+
'TxOutputScript',
69+
'VertexId',
70+
]);
71+
6272
/**
6373
* Single type names
6474
*/
6575
export const NanoContractArgumentSingleTypeNameSchema = z.enum([
6676
'bool',
67-
'bytes',
6877
'int',
6978
'str',
70-
'Address',
71-
'BlueprintId',
72-
'ContractId',
7379
'Timestamp',
74-
'TokenUid',
75-
'TxOutputScript',
7680
'VarInt',
77-
'VertexId',
81+
...NanoContractArgumentByteTypes.options,
7882
]);
7983
export type NanoContractArgumentSingleTypeName = z.output<
8084
typeof NanoContractArgumentSingleTypeNameSchema

0 commit comments

Comments
 (0)