Skip to content

Commit

Permalink
feat: Imported transactions unit tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-sekanina committed Apr 28, 2022
1 parent 6414362 commit 7bd9e0d
Show file tree
Hide file tree
Showing 47 changed files with 1,360 additions and 621 deletions.
Binary file modified .gradle/6.6/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.6/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/6.6/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/6.6/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/6.6/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/6.6/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/6.6/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
9 changes: 0 additions & 9 deletions .idea/PSBT.iml

This file was deleted.

407 changes: 301 additions & 106 deletions applet/build/reports/tests/test/classes/tests.AppletTest.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions applet/build/reports/tests/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>Test Summary</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.157s</div>
<div class="counter">0.314s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -85,7 +85,7 @@ <h2>Packages</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.157s</td>
<td>0.314s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -112,7 +112,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.157s</td>
<td>0.314s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -126,7 +126,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 6.6</a> at 18 Mar 2022, 4:14:08 PM</p>
<a href="http://www.gradle.org">Gradle 6.6</a> at 28 Apr 2022, 3:02:31 AM</p>
</div>
</div>
</body>
Expand Down
6 changes: 3 additions & 3 deletions applet/build/reports/tests/test/packages/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1>Package tests</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.157s</div>
<div class="counter">0.314s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -83,7 +83,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.157s</td>
<td>0.314s</td>
<td class="success">100%</td>
</tr>
</table>
Expand All @@ -96,7 +96,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 6.6</a> at 18 Mar 2022, 4:14:08 PM</p>
<a href="http://www.gradle.org">Gradle 6.6</a> at 28 Apr 2022, 3:02:31 AM</p>
</div>
</div>
</body>
Expand Down
405 changes: 300 additions & 105 deletions applet/build/test-results/test/TEST-tests.AppletTest.xml

Large diffs are not rendered by default.

402 changes: 299 additions & 103 deletions applet/build/test-results/test/binary/output.bin

Large diffs are not rendered by default.

Binary file modified applet/build/test-results/test/binary/output.bin.idx
Binary file not shown.
Binary file modified applet/build/test-results/test/binary/results.bin
Binary file not shown.
24 changes: 14 additions & 10 deletions applet/build/tmp/compileJava/source-classes-mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ applet/GeneralMap.java
applet.GeneralMap
applet/AppletInstructions.java
applet.AppletInstructions
applet/SekripkInstructions.java
applet.SekripkInstructions
applet/KeyPair.java
applet.KeyPair
applet/SecretAndTimeStorage.java
applet.SecretAndTimeStorage
applet/GlobalMap.java
applet.GlobalMap
applet/GlobalUnsignedTX.java
applet.GlobalUnsignedTX
applet/GlobalUnsignedTXOutput.java
applet.GlobalUnsignedTXOutput
applet/PSBT.java
applet.PSBT
applet/GlobalUnsignedTXInput.java
applet.GlobalUnsignedTXInput
applet/SekriptInstructions.java
applet.SekriptInstructions
applet/Policy.java
applet.Policy
applet/GlobalMap.java
applet.GlobalMap
applet/PSBT.java
applet.PSBT
applet/Stack.java
applet.Stack
applet/SecretAndTimeStorage.java
applet.SecretAndTimeStorage
applet/FromApplet.java
applet.FromApplet
applet/GlobalUnsignedTXOutput.java
applet.GlobalUnsignedTXOutput
applet/MainApplet.java
applet.MainApplet
14 changes: 8 additions & 6 deletions applet/build/tmp/compileTestJava/source-classes-mapping.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
tests/MyUpload.java
tests.MyUpload
tests/TransactionsImported.java
tests.TransactionsImported
tests/AppletTest.java
tests.AppletTest
tests/Upload.java
tests.Upload
tests/MyTests.java
tests.MyTests
tests/BaseTest.java
tests.BaseTest
tests/TransactionsImported.java
tests.TransactionsImported
tests/AppletTest.java
tests.AppletTest
tests/ImpTrxUnitTests.java
tests.ImpTrxUnitTests
22 changes: 17 additions & 5 deletions applet/src/main/java/applet/AppletInstructions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* <p>
* Still very useful for testing and overseeing I hope.
* <p>
* I might consider transforming it to hashtable or more sophisticated data structure later on
* I might consider transforming it to hashtable or more sophisticated data structure later on // this one aged well
*/

public class AppletInstructions {
public AppletInstructions() {
}

public final short PACKET_BUFFER_SIZE = 250; // amount of data received in one packet
public static final short PACKET_BUFFER_SIZE = 250; // amount of data received in one packet


/**
Expand All @@ -26,14 +26,26 @@ public AppletInstructions() {
* applet initialization
*/

public static final short INSTRUCTION_VERSION = 1;


public static final short CLASS_PSBT_UPLOAD = 0;
// one array of size of AppletInstruction.APDU_PACKET_SIZE is sent back as control data

public static final short CLASS_POLICY_UPLOAD = 1;
public static final short CLASS_SECRETandTIME_UPLOAD = 2; // p1 will determine reference, where to store it

public final short INS_REQUEST = 0;
public final short INS_UPLOAD = 1;
public final short INS_FINISH = 2;
public static final short HAND_SHAKE = 3;
// simple scenario where applet returns "HAND SHAKE" in bytes


public static final short CLASS_PSBT_UPLOAD_AND_BACK = 4;
// scenario where applet parses the PSBT and then sends it back
// to implement this one will take greater changes in how upload works. Different upload might need to be implemented

public static final short INS_REQUEST = 0;
public static final short INS_UPLOAD = 1;
public static final short INS_FINISH = 2;

//global keytype bytes below
public static final byte PSBT_GLOBAL_UNSIGNED_TX = 0x00;
Expand Down
19 changes: 19 additions & 0 deletions applet/src/main/java/applet/FromApplet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package applet;

import javacard.framework.APDU;
import javacard.framework.Util;
import static applet.MainApplet.PSBTdata;

public class FromApplet {
/**
* should be used for small amount of data of size of one packet max
* @param apdu apdu used for communication
* @param array array of data to send
*/
static void send_data(APDU apdu, byte[] array)
{
Util.arrayCopyNonAtomic(array, (short) 0, apdu.getBuffer(), (short) 0, (short) array.length);
apdu.setOutgoingAndSend((short) 0, (short) array.length);
}

}
16 changes: 8 additions & 8 deletions applet/src/main/java/applet/GeneralMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

public class GeneralMap {
public short NUM_OF_KEYPAIR = 8;
public short currentKeyPair = -1;
public KeyPair[] keyPairs = new KeyPair[NUM_OF_KEYPAIR];
public short mapSize = 0;
public short current_key_pair = -1;
public KeyPair[] key_pairs = new KeyPair[NUM_OF_KEYPAIR];
public short map_size = 0;

public GeneralMap() {
short i = 0;
while (i < NUM_OF_KEYPAIR) {
keyPairs[i] = new KeyPair();
key_pairs[i] = new KeyPair();
i++;
}
}

public void fillUp(short arrayIndex) {
while ((PSBTdata[arrayIndex + mapSize] & 0xff) != 0x00 && currentKeyPair < NUM_OF_KEYPAIR - 1) {
currentKeyPair++;
while ((PSBTdata[arrayIndex + map_size] & 0xff) != 0x00 && current_key_pair < NUM_OF_KEYPAIR - 1) {
current_key_pair++;
//System.out.print("mapsize = " + mapSize + System.lineSeparator());
//System.out.print("arrayIndex = " + arrayIndex + System.lineSeparator());
keyPairs[currentKeyPair].fill((short) (arrayIndex + mapSize));
mapSize += keyPairs[currentKeyPair].getSize();
key_pairs[current_key_pair].fill((short) (arrayIndex + map_size));
map_size += key_pairs[current_key_pair].getSize();
//System.out.print("currentKeyPairSize = " + keyPairs[currentKeyPair].getSize() + System.lineSeparator());
//System.out.print("mapsize = " + mapSize + System.lineSeparator());
//System.out.print("arrayIndex = " + arrayIndex + System.lineSeparator());
Expand Down
36 changes: 18 additions & 18 deletions applet/src/main/java/applet/GlobalMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
import static applet.MainApplet.PSBTdata;

public class GlobalMap extends GeneralMap {
Short numOfInputMaps = null;
Short numOfOutputMaps = null;
Short input_maps_total = null;
Short output_maps_total = null;
Short PSBTversion = null;
//PGU_TX_keypair fancyKeyPairInfo = new PGU_TX_keypair();
GlobalUnsignedTX globalUnsignedTX = new GlobalUnsignedTX();

public void fillUp(short arrayIndex) {
while ((PSBTdata[arrayIndex + mapSize] & 0xff) != 0x00 && currentKeyPair < NUM_OF_KEYPAIR - 1) {
currentKeyPair++;
keyPairs[currentKeyPair].fill((short) (arrayIndex + mapSize));
while ((PSBTdata[arrayIndex + map_size] & 0xff) != 0x00 && current_key_pair < NUM_OF_KEYPAIR - 1) {
current_key_pair++;
key_pairs[current_key_pair].fill((short) (arrayIndex + map_size));

if (keyPairs[currentKeyPair].key.keyType == PSBT_GLOBAL_UNSIGNED_TX) {
if (key_pairs[current_key_pair].key.key_type == PSBT_GLOBAL_UNSIGNED_TX) {
assert PSBTversion == null || PSBTversion != 2;
globalUnsignedTX.fill((short) (arrayIndex + mapSize + 2 +
keyPairs[currentKeyPair].value.valueLenBytes));
assert globalUnsignedTX.size == keyPairs[currentKeyPair].value.valueLen;
globalUnsignedTX.fill((short) (arrayIndex + map_size + 2 +
key_pairs[current_key_pair].value.value_len_bytes));
assert globalUnsignedTX.size == key_pairs[current_key_pair].value.value_len;
System.out.print("PSBTv0 parsed" + System.lineSeparator());
}

if (keyPairs[currentKeyPair].key.keyType == PSBT_GLOBAL_INPUT_COUNT) {
numOfInputMaps = (short) keyPairs[currentKeyPair].value.getByte((short) 0);
if (key_pairs[current_key_pair].key.key_type == PSBT_GLOBAL_INPUT_COUNT) {
input_maps_total = (short) key_pairs[current_key_pair].value.getByte((short) 0);
}

if (keyPairs[currentKeyPair].key.keyType == PSBT_GLOBAL_OUTPUT_COUNT) {
numOfOutputMaps = (short) keyPairs[currentKeyPair].value.getByte((short) 0);
if (key_pairs[current_key_pair].key.key_type == PSBT_GLOBAL_OUTPUT_COUNT) {
output_maps_total = (short) key_pairs[current_key_pair].value.getByte((short) 0);
}

if (keyPairs[currentKeyPair].key.keyType == PSBT_GLOBAL_TX_VERSION) {
PSBTversion = (short) keyPairs[currentKeyPair].value.getByte((short) 3);
if (key_pairs[current_key_pair].key.key_type == PSBT_GLOBAL_TX_VERSION) {
PSBTversion = (short) key_pairs[current_key_pair].value.getByte((short) 3);
assert PSBTversion != 2 || globalUnsignedTX.start == null;
}

// TODO maybe add more special key types here later on

mapSize += keyPairs[currentKeyPair].getSize();
map_size += key_pairs[current_key_pair].getSize();
}
System.out.print("numOfInputMap: " + numOfInputMaps + System.lineSeparator());
System.out.print("numOfOutputMaps: " + numOfOutputMaps + System.lineSeparator());
System.out.print("input_map_total: " + input_maps_total + System.lineSeparator());
System.out.print("output_map_total: " + output_maps_total + System.lineSeparator());
}
}
27 changes: 15 additions & 12 deletions applet/src/main/java/applet/GlobalUnsignedTX.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package applet;

import static applet.MainApplet.PSBTdata;
import static applet.MainApplet.controlArray;
import static applet.Tools.byteSizeOfCWI;
import static applet.Tools.compactWeirdoInt;

Expand All @@ -15,10 +16,10 @@ public class GlobalUnsignedTX {
Short version = null;
short size = 0;

Short inputCount = null;
Short input_count = null;
GlobalUnsignedTXInput[] inputs = new GlobalUnsignedTXInput[MAX_COUNT_OF_IO];

Short outputCount = null;
Short output_count = null;
GlobalUnsignedTXOutput[] outputs = new GlobalUnsignedTXOutput[MAX_COUNT_OF_IO];

Short lockTimeStart = null;
Expand All @@ -34,21 +35,23 @@ public void fill(short arrayIndex){
start = arrayIndex;
version = (short) PSBTdata[start];
size += 4;
inputCount = getCount();
size += byteSizeOfCWI(inputCount);
input_count = getCount();
controlArray[0] = (byte) getCount();
size += byteSizeOfCWI(input_count);

assert (inputCount) <= MAX_COUNT_OF_IO;
assert (input_count) <= MAX_COUNT_OF_IO;

for (short i = 0; i < inputCount; i++) {
for (short i = 0; i < input_count; i++) {
inputs[i].fill((short) (start + size));
size += inputs[i].size;
}

outputCount = getCount();
assert outputCount <= MAX_COUNT_OF_IO;
size += byteSizeOfCWI(outputCount);
output_count = getCount();
controlArray[1] = (byte) getCount();
assert output_count <= MAX_COUNT_OF_IO;
size += byteSizeOfCWI(output_count);

for (short i = 0; i < outputCount; i++) {
for (short i = 0; i < output_count; i++) {
outputs[i].fill((short)(start + size));
size += outputs[i].size;
}
Expand All @@ -65,8 +68,8 @@ void print(){
System.out.print("starts at: " + start + System.lineSeparator());
System.out.print("version: " + version + System.lineSeparator());
System.out.print("size: " + size + System.lineSeparator());
System.out.print("input count: " + inputCount + System.lineSeparator());
System.out.print("output count: " + outputCount + System.lineSeparator());
System.out.print("input count: " + input_count + System.lineSeparator());
System.out.print("output count: " + output_count + System.lineSeparator());
System.out.print("lockTimeStart: " + lockTimeStart + System.lineSeparator());
}

Expand Down
Loading

0 comments on commit 7bd9e0d

Please sign in to comment.