Skip to content

Commit

Permalink
feat: fixxed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-sekanina committed Nov 4, 2022
1 parent 70da45e commit d9315d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
16 changes: 16 additions & 0 deletions applet/src/main/java/main/AppletControl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package main;

import applet.AppletInstructions;
import applet.MainApplet;
import com.licel.jcardsim.base.CardManager;
import com.licel.jcardsim.base.Simulator;
import com.licel.jcardsim.smartcardio.CardSimulator;
import com.licel.jcardsim.utils.AIDUtil;
import javacard.framework.AID;

import java.util.Arrays;

public class AppletControl {
Expand Down Expand Up @@ -50,21 +54,33 @@ public void AppletDebugV0() throws Exception {

public AppletControl(String psbt) throws Exception {
simulator = new CardSimulator();
AID appletAID = AIDUtil.create("F000000001");
simulator.installApplet(appletAID, MainApplet.class);
simulator.selectApplet(appletAID);
this.psbt = fromHex(psbt);
}

public AppletControl(CardSimulator sim, String psbt) throws Exception {
simulator = sim;
AID appletAID = AIDUtil.create("F000000001");
simulator.installApplet(appletAID, MainApplet.class);
simulator.selectApplet(appletAID);
this.psbt = fromHex(psbt);
}

public AppletControl(CardSimulator sim, byte[] psbt) throws Exception {
simulator = sim;
AID appletAID = AIDUtil.create("F000000001");
simulator.installApplet(appletAID, MainApplet.class);
simulator.selectApplet(appletAID);
this.psbt = psbt;
}

public AppletControl(byte[] psbt) throws Exception {
simulator = new CardSimulator();
AID appletAID = AIDUtil.create("F000000001");
simulator.installApplet(appletAID, MainApplet.class);
simulator.selectApplet(appletAID);
this.psbt = psbt;
}

Expand Down
9 changes: 5 additions & 4 deletions applet/src/main/java/main/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@

public class Run {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
// ./gradlew run --args="arg1 arg2 arg3"
System.out.print("Enter a PSBT transaction: " + System.lineSeparator());
String psbt = TransactionsImported.validTransaction8; //sc.nextLine();
String psbt = TransactionsImported.validTransaction8;
System.out.print("You entered a following transaction:" + System.lineSeparator());
System.out.print(psbt + System.lineSeparator());
System.out.print(System.lineSeparator());

// 1. create simulator
CardSimulator simulator = new CardSimulator();
/**
// 2. install applet
AID appletAID = AIDUtil.create("F000000001");
simulator.installApplet(appletAID, MainApplet.class);
// 3. select applet
simulator.selectApplet(appletAID);
simulator.selectApplet(appletAID);*/

// 4. send APDU
AppletControl ap = new AppletControl(simulator, psbt);
AppletControl ap = new AppletControl(simulator, args[0]);
ap.UploadTransaction();
ap.DownloadDebugV0();
}
Expand Down
9 changes: 6 additions & 3 deletions applet/src/test/java/tests/AppletTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package tests;

import applet.MainApplet;
import com.licel.jcardsim.smartcardio.CardSimulator;
import com.licel.jcardsim.utils.AIDUtil;
import javacard.framework.AID;
import main.Download;
import main.Upload;
import main.AppletControl;
Expand Down Expand Up @@ -86,9 +89,9 @@ public void hel() throws Exception {
@Test
public void transaction1() throws Exception {
byte[] transaction = AppletControl.fromHex(TransactionsImported.validTransaction1);
Download download = new Download();
CardSimulator simulator = new CardSimulator();
AppletControl ac = new AppletControl(simulator, transaction);
Download download = new Download();
ac.UploadTransaction();
assert download.downloadNumOfInp(simulator) == 1;
assert download.downloadNumOfOut(simulator) == 2;
Expand Down Expand Up @@ -116,8 +119,8 @@ public void transaction3() throws Exception {
assert download.downloadNumOfOut(simulator) == 2;
}

@Test
static void runAllTests() throws Exception {
//@Test
public void runAllTests() throws Exception {
transactionTestTemplate((byte) 1, (byte) 2, AppletControl.fromHex(TransactionsImported.validTransaction1));
// Case: PSBT with one P2PKH input. Outputs are empty

Expand Down

0 comments on commit d9315d4

Please sign in to comment.