File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
src/Serialization/TransactionBody
test/Serialization/TransactionBody Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ export class Value {
8181 const reader = new CborReader ( cbor ) ;
8282
8383 if ( reader . peekState ( ) === CborReaderState . UnsignedInteger ) {
84- const coins = reader . readInt ( ) ;
84+ const coins = reader . readUInt ( ) ;
8585 return new Value ( coins ) ;
8686 }
8787
@@ -93,7 +93,7 @@ export class Value {
9393 `Expected an array of ${ VALUE_ARRAY_SIZE } elements, but got an array of ${ length } elements`
9494 ) ;
9595
96- const coins = reader . readInt ( ) ;
96+ const coins = reader . readUInt ( ) ;
9797 const multiassets = new Map < Crypto . Hash28ByteBase16 , Map < Cardano . AssetName , bigint > > ( ) ;
9898
9999 reader . readStartMap ( ) ;
@@ -105,7 +105,7 @@ export class Value {
105105 reader . readStartMap ( ) ;
106106 while ( reader . peekState ( ) !== CborReaderState . EndMap ) {
107107 const assetName = Buffer . from ( reader . readByteString ( ) ) . toString ( 'hex' ) as unknown as Cardano . AssetName ;
108- const quantity = reader . readInt ( ) ;
108+ const quantity = reader . readUInt ( ) ;
109109
110110 multiassets . get ( scriptHash ) ! . set ( assetName , quantity ) ;
111111 }
Original file line number Diff line number Diff line change 11/* eslint-disable sonarjs/no-duplicate-string */
22import * as Cardano from '../../../src/Cardano' ;
3+ import { CborContentException , Value } from '../../../src/Serialization' ;
34import { HexBlob } from '@cardano-sdk/util' ;
4- import { Value } from '../../../src/Serialization' ;
55
66// Test data used in the following tests was generated with the cardano-serialization-lib
77
88const cbor = HexBlob (
99 '821a000f4240a2581c00000000000000000000000000000000000000000000000000000000a3443031323218644433343536186344404142420a581c11111111111111111111111111111111111111111111111111111111a3443031323218644433343536186344404142420a'
1010) ;
1111
12+ const cborWithNegativeCoin = HexBlob (
13+ '823a000f423fa2581c00000000000000000000000000000000000000000000000000000000a3443031323218644433343536186344404142420a581c11111111111111111111111111111111111111111111111111111111a3443031323218644433343536186344404142420a'
14+ ) ;
15+
1216const unsortedCore = {
1317 assets : new Map ( [
1418 [ '1111111111111111111111111111111111111111111111111111111140414242' as unknown as Cardano . AssetId , 10n ] ,
@@ -91,4 +95,8 @@ describe('Value', () => {
9195 const interval = Value . fromCbor ( onlyLovelaceCbor ) ;
9296 expect ( interval . toCore ( ) ) . toEqual ( onlyLovelaceCore ) ;
9397 } ) ;
98+
99+ it ( 'can throws if Value CBOR contains negative numbers' , ( ) => {
100+ expect ( ( ) => Value . fromCbor ( cborWithNegativeCoin ) ) . toThrow ( CborContentException ) ;
101+ } ) ;
94102} ) ;
You can’t perform that action at this time.
0 commit comments