@@ -180,8 +180,10 @@ public void decodePositiveN_forZero_throwsIAE() {
180
180
@ Test
181
181
public void decodePositiveN_forNumberWithoutMinimalEncoding_throwsIAE () {
182
182
byte zero = 0x00 ;
183
- for (int n =0 ; n <20 ; n ++) {
184
- int i = (1 << n ); // i = (2^n)
183
+
184
+ // from 1 to 15, numbers are small numbers and therefore pushed as opcodes
185
+ // with null chunk data
186
+ for (int i =1 ; i <16 ; i ++) {
185
187
byte [] numWithoutMinimalEncoding = new byte [] {(byte ) i , zero };
186
188
187
189
ScriptBuilder builder = new ScriptBuilder ();
@@ -192,6 +194,23 @@ public void decodePositiveN_forNumberWithoutMinimalEncoding_throwsIAE() {
192
194
assertFalse (chunk .isPositiveN ());
193
195
assertThrows (IllegalArgumentException .class , chunk ::decodePositiveN );
194
196
}
197
+
198
+ for (int n =4 ; n <20 ; n ++) {
199
+ int i = (1 << n ); // i = (2^n)
200
+ ScriptBuilder builder = new ScriptBuilder ();
201
+ ScriptChunk chunk = builder .number (i ).build ().getChunks ().get (0 );
202
+ byte [] chunkData = chunk .data ;
203
+
204
+ // add zero padding so the number does not have minimal encoding
205
+ byte [] numWithoutMinimalEncoding = Arrays .copyOf (chunkData , chunkData .length + 1 );
206
+ numWithoutMinimalEncoding [chunkData .length ] = zero ;
207
+
208
+ // build the chunk for the number without minimal encoding
209
+ builder = new ScriptBuilder ();
210
+ ScriptChunk newChunk = builder .data (numWithoutMinimalEncoding ).build ().chunks .get (0 );
211
+ assertFalse (newChunk .isPositiveN ());
212
+ assertThrows (IllegalArgumentException .class , newChunk ::decodePositiveN );
213
+ }
195
214
}
196
215
197
216
@ Test
0 commit comments