@@ -13,19 +13,21 @@ import { mockBrand } from './mockBrand.js';
13
13
test ( 'natMathHelpers make' , t => {
14
14
t . deepEqual ( m . make ( mockBrand , 4n ) , { brand : mockBrand , value : 4n } ) ;
15
15
// @ts -ignore deliberate invalid arguments for testing
16
- t . deepEqual ( m . make ( mockBrand , 4 ) , { brand : mockBrand , value : 4n } ) ;
16
+ t . throws ( ( ) => m . make ( mockBrand , 4 ) , {
17
+ message : 'value 4 must be a bigint or an array, not "number"' ,
18
+ } ) ;
17
19
t . throws (
18
20
// @ts -ignore deliberate invalid arguments for testing
19
21
( ) => m . make ( mockBrand , 'abc' ) ,
20
22
{
21
- message : / v a l u e . * m u s t b e a N a t o r a n a r r a y / ,
23
+ message : ' value "abc" must be a bigint or an array, not "string"' ,
22
24
} ,
23
25
`'abc' is not a nat` ,
24
26
) ;
25
27
t . throws (
26
28
// @ts -ignore deliberate invalid arguments for testing
27
29
( ) => m . make ( mockBrand , - 1 ) ,
28
- { message : / v a l u e . * m u s t b e a N a t o r a n a r r a y / } ,
30
+ { message : ' value -1 must be a bigint or an array, not "number"' } ,
29
31
`- 1 is not a valid Nat` ,
30
32
) ;
31
33
} ) ;
@@ -35,15 +37,15 @@ test('natMathHelpers make no brand', t => {
35
37
// @ts -ignore deliberate invalid arguments for testing
36
38
( ) => m . make ( 4n ) ,
37
39
{
38
- message : / T h e b r a n d " \ [4 n \ ]" d o e s n ' t l o o k l i k e a b r a n d . / ,
40
+ message : '" brand" " [4n]" must be a remotable, not "bigint"' ,
39
41
} ,
40
42
`brand is required in make` ,
41
43
) ;
42
44
} ) ;
43
45
44
46
test ( 'natMathHelpers coerce' , t => {
45
47
t . deepEqual (
46
- m . coerce ( mockBrand , { brand : mockBrand , value : 4n } ) ,
48
+ m . coerce ( mockBrand , harden ( { brand : mockBrand , value : 4n } ) ) ,
47
49
{
48
50
brand : mockBrand ,
49
51
value : 4n ,
@@ -52,14 +54,17 @@ test('natMathHelpers coerce', t => {
52
54
) ;
53
55
t . throws (
54
56
( ) =>
55
- m . coerce ( mockBrand , {
56
- brand : Far ( 'otherBrand' , {
57
- getAllegedName : ( ) => 'somename' ,
58
- isMyIssuer : async ( ) => false ,
59
- getDisplayInfo : ( ) => ( { assetKind : AssetKind . NAT } ) ,
57
+ m . coerce (
58
+ mockBrand ,
59
+ harden ( {
60
+ brand : Far ( 'otherBrand' , {
61
+ getAllegedName : ( ) => 'somename' ,
62
+ isMyIssuer : async ( ) => false ,
63
+ getDisplayInfo : ( ) => ( { assetKind : AssetKind . NAT } ) ,
64
+ } ) ,
65
+ value : 4n ,
60
66
} ) ,
61
- value : 4n ,
62
- } ) ,
67
+ ) ,
63
68
{
64
69
message : / T h e b r a n d i n t h e a l l e g e d A m o u n t .* i n ' c o e r c e ' d i d n ' t m a t c h t h e s p e c i f i e d b r a n d / ,
65
70
} ,
@@ -69,7 +74,7 @@ test('natMathHelpers coerce', t => {
69
74
// @ts -ignore deliberate invalid arguments for testing
70
75
( ) => m . coerce ( 3n , mockBrand ) ,
71
76
{
72
- message : / T h e a m o u n t . * d o e s n ' t l o o k l i k e a n a m o u n t . D i d y o u p a s s a v a l u e i n s t e a d ? / ,
77
+ message : '"brand" "[3n]" must be a remotable, not "bigint"' ,
73
78
} ,
74
79
`coerce needs a brand` ,
75
80
) ;
@@ -80,7 +85,7 @@ test('natMathHelpers coerce no brand', t => {
80
85
// @ts -ignore deliberate invalid arguments for testing
81
86
( ) => m . coerce ( m . make ( 4n , mockBrand ) ) ,
82
87
{
83
- message : / T h e b r a n d { " b r a n d " : " \[ A l l e g e d : b r a n d \] " , " v a l u e " : " \ [4 n \] " } d o e s n ' t l o o k l i k e a b r a n d . / ,
88
+ message : ' "brand" " [4n]" must be a remotable, not "bigint"' ,
84
89
} ,
85
90
`brand is required in coerce` ,
86
91
) ;
@@ -89,15 +94,17 @@ test('natMathHelpers coerce no brand', t => {
89
94
test ( 'natMathHelpers getValue' , t => {
90
95
t . is ( m . getValue ( mockBrand , m . make ( mockBrand , 4n ) ) , 4n ) ;
91
96
// @ts -ignore deliberate invalid arguments for testing
92
- t . is ( m . getValue ( mockBrand , m . make ( mockBrand , 4 ) ) , 4n ) ;
97
+ t . throws ( ( ) => m . getValue ( mockBrand , m . make ( mockBrand , 4 ) ) , {
98
+ message : 'value 4 must be a bigint or an array, not "number"' ,
99
+ } ) ;
93
100
} ) ;
94
101
95
102
test ( 'natMathHelpers getValue no brand' , t => {
96
103
t . throws (
97
104
// @ts -ignore deliberate invalid arguments for testing
98
105
( ) => m . getValue ( m . make ( 4n , mockBrand ) ) ,
99
106
{
100
- message : / T h e b r a n d { " b r a n d " : " \[ A l l e g e d : b r a n d \] " , " v a l u e " : " \ [4 n \] " } d o e s n ' t l o o k l i k e a b r a n d . / ,
107
+ message : ' "brand" " [4n]" must be a remotable, not "bigint"' ,
101
108
} ,
102
109
`brand is required in getValue` ,
103
110
) ;
@@ -114,38 +121,44 @@ test('natMathHelpers makeEmpty no brand', t => {
114
121
// @ts -ignore deliberate invalid arguments for testing
115
122
( ) => m . makeEmpty ( AssetKind . NAT ) ,
116
123
{
117
- message : / T h e b r a n d . * d o e s n ' t l o o k l i k e a b r a n d . / ,
124
+ message : '" brand" "nat" must be a remotable, not "string"' ,
118
125
} ,
119
126
`make empty no brand` ,
120
127
) ;
121
128
} ) ;
122
129
123
130
test ( 'natMathHelpers isEmpty' , t => {
124
- t . assert ( m . isEmpty ( { brand : mockBrand , value : 0n } ) , `isEmpty(0) is true` ) ;
125
- t . falsy ( m . isEmpty ( { brand : mockBrand , value : 6n } ) , `isEmpty(6) is false` ) ;
131
+ t . assert (
132
+ m . isEmpty ( harden ( { brand : mockBrand , value : 0n } ) ) ,
133
+ `isEmpty(0) is true` ,
134
+ ) ;
135
+ t . falsy (
136
+ m . isEmpty ( harden ( { brand : mockBrand , value : 6n } ) ) ,
137
+ `isEmpty(6) is false` ,
138
+ ) ;
126
139
t . assert ( m . isEmpty ( m . make ( mockBrand , 0n ) ) , `isEmpty(0) is true` ) ;
127
140
t . falsy ( m . isEmpty ( m . make ( mockBrand , 6n ) ) , `isEmpty(6) is false` ) ;
128
141
t . throws (
129
142
// @ts -ignore deliberate invalid arguments for testing
130
143
( ) => m . isEmpty ( 'abc' ) ,
131
144
{
132
- message : / T h e a m o u n t . * d o e s n ' t l o o k l i k e a n a m o u n t . D i d y o u p a s s a v a l u e i n s t e a d ? / ,
145
+ message : '" amount" "abc" must be a pass-by-copy record, not "string"' ,
133
146
} ,
134
147
`isEmpty('abc') throws because it cannot be coerced` ,
135
148
) ;
136
149
t . throws (
137
150
// @ts -ignore deliberate invalid arguments for testing
138
- ( ) => m . isEmpty ( { brand : mockBrand , value : 'abc' } ) ,
151
+ ( ) => m . isEmpty ( harden ( { brand : mockBrand , value : 'abc' } ) ) ,
139
152
{
140
- message : / v a l u e . * m u s t b e a N a t o r a n a r r a y / ,
153
+ message : ' value "abc" must be a bigint or an array, not "string"' ,
141
154
} ,
142
155
`isEmpty('abc') throws because it cannot be coerced` ,
143
156
) ;
144
157
t . throws (
145
158
// @ts -ignore deliberate invalid arguments for testing
146
159
( ) => m . isEmpty ( 0n ) ,
147
160
{
148
- message : / T h e a m o u n t . * d o e s n ' t l o o k l i k e a n a m o u n t . D i d y o u p a s s a v a l u e i n s t e a d ? / ,
161
+ message : '" amount" "[0n]" must be a pass-by-copy record, not "bigint"' ,
149
162
} ,
150
163
`isEmpty(0) throws because it cannot be coerced` ,
151
164
) ;
@@ -155,7 +168,10 @@ test('natMathHelpers isGTE', t => {
155
168
t . assert ( m . isGTE ( m . make ( mockBrand , 5n ) , m . make ( mockBrand , 3n ) ) , `5 >= 3` ) ;
156
169
t . assert ( m . isGTE ( m . make ( mockBrand , 3n ) , m . make ( mockBrand , 3n ) ) , `3 >= 3` ) ;
157
170
t . falsy (
158
- m . isGTE ( { brand : mockBrand , value : 3n } , { brand : mockBrand , value : 4n } ) ,
171
+ m . isGTE (
172
+ harden ( { brand : mockBrand , value : 3n } ) ,
173
+ harden ( { brand : mockBrand , value : 4n } ) ,
174
+ ) ,
159
175
`3 < 4` ,
160
176
) ;
161
177
} ) ;
0 commit comments