-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement standard checks for BIP62 shortest possible data push rules…
…. Also fix ScriptBuilder so it doesn't build longer than necessary data pushes any more.
- Loading branch information
1 parent
7b24a72
commit ccc3dbd
Showing
4 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/src/test/java/com/google/bitcoin/script/ScriptChunkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright 2014 Andreas Schildbach | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.bitcoin.script; | ||
|
||
import static com.google.bitcoin.script.ScriptOpCodes.OP_PUSHDATA1; | ||
import static com.google.bitcoin.script.ScriptOpCodes.OP_PUSHDATA2; | ||
import static com.google.bitcoin.script.ScriptOpCodes.OP_PUSHDATA4; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class ScriptChunkTest { | ||
|
||
@Test | ||
public void testShortestPossibleDataPush() { | ||
assertTrue("empty push", new ScriptBuilder().data(new byte[0]).build().getChunks().get(0) | ||
.isShortestPossiblePushData()); | ||
|
||
for (byte i = -1; i < 127; i++) | ||
assertTrue("push of single byte " + i, new ScriptBuilder().data(new byte[] { i }).build().getChunks() | ||
.get(0).isShortestPossiblePushData()); | ||
|
||
for (int len = 2; len < Script.MAX_SCRIPT_ELEMENT_SIZE; len++) | ||
assertTrue("push of " + len + " bytes", new ScriptBuilder().data(new byte[len]).build().getChunks().get(0) | ||
.isShortestPossiblePushData()); | ||
|
||
// non-standard chunks | ||
for (byte i = 1; i <= 16; i++) | ||
assertFalse("push of smallnum " + i, new ScriptChunk(1, new byte[] { i }).isShortestPossiblePushData()); | ||
assertFalse("push of 75 bytes", new ScriptChunk(OP_PUSHDATA1, new byte[75]).isShortestPossiblePushData()); | ||
assertFalse("push of 255 bytes", new ScriptChunk(OP_PUSHDATA2, new byte[255]).isShortestPossiblePushData()); | ||
assertFalse("push of 65535 bytes", new ScriptChunk(OP_PUSHDATA4, new byte[65535]).isShortestPossiblePushData()); | ||
} | ||
} |