make simulator work again

This commit is contained in:
Michele Balistreri 2019-09-02 13:30:27 +03:00
parent 5e0bcc8bbb
commit 7473390715
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 29 additions and 8 deletions

View File

@ -62,6 +62,7 @@ dependencies {
} }
test { test {
classpath = sourceSets.test.runtimeClasspath.filter { f -> f.name != "api_classic.jar" }
useJUnitPlatform { useJUnitPlatform {
excludeTags 'manual' excludeTags 'manual'
} }
@ -95,6 +96,6 @@ afterEvaluate {
jvmArgs.push('-noverify') jvmArgs.push('-noverify')
} }
def junitPlatformTestTask = tasks.getByName('test') def testTask = tasks.getByName('test')
junitPlatformTestTask.jvmArgs(jvmArgs) testTask.jvmArgs(jvmArgs)
} }

View File

@ -30,6 +30,7 @@ import org.web3j.utils.Convert;
import org.web3j.utils.Numeric; import org.web3j.utils.Numeric;
import javax.smartcardio.*; import javax.smartcardio.*;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -129,13 +130,32 @@ public class KeycardTest {
private static void openSimulatorChannel() throws Exception { private static void openSimulatorChannel() throws Exception {
simulator = new CardSimulator(); simulator = new CardSimulator();
AID appletAID = AIDUtil.create(Identifiers.getKeycardInstanceAID());
AID ndefAID = AIDUtil.create(Identifiers.NDEF_AID);
AID cashAID = AIDUtil.create(Identifiers.CASH_AID);
simulator.installApplet(appletAID, KeycardApplet.class); // Install KeycardApplet
simulator.installApplet(ndefAID, NDEFApplet.class); AID aid = AIDUtil.create(Identifiers.KEYCARD_AID);
simulator.installApplet(cashAID, CashApplet.class); ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(Identifiers.getKeycardInstanceAID().length);
bos.write(Identifiers.getKeycardInstanceAID());
simulator.installApplet(aid, KeycardApplet.class, bos.toByteArray(), (short) 0, (byte) bos.size());
bos.reset();
// Install NDEFApplet
aid = AIDUtil.create(Identifiers.NDEF_AID);
bos.write(Identifiers.NDEF_INSTANCE_AID.length);
bos.write(Identifiers.NDEF_INSTANCE_AID);
bos.write(new byte[] {0x01, 0x00, 0x02, (byte) 0xC9, 0x00});
simulator.installApplet(aid, NDEFApplet.class, bos.toByteArray(), (short) 0, (byte) bos.size());
bos.reset();
// Install CashApplet
aid = AIDUtil.create(Identifiers.CASH_AID);
bos.write(Identifiers.CASH_INSTANCE_AID.length);
bos.write(Identifiers.CASH_INSTANCE_AID);
simulator.installApplet(aid, CashApplet.class, bos.toByteArray(), (short) 0, (byte) bos.size());
bos.reset();
cardTerminal = CardTerminalSimulator.terminal(simulator); cardTerminal = CardTerminalSimulator.terminal(simulator);