Added tests and code improvements

This commit is contained in:
2016-04-08 19:22:40 +02:00
parent f70c15da38
commit 4f7f80c12a
46 changed files with 163 additions and 43 deletions

View File

@ -60,6 +60,9 @@ public class WifExporter {
section.add("label", identity.getAlias());
section.add("enabled", true);
section.add("decoy", false);
if (identity.isChan()) {
section.add("chan", identity.isChan());
}
section.add("noncetrialsperbyte", identity.getPubkey().getNonceTrialsPerByte());
section.add("payloadlengthextrabytes", identity.getPubkey().getExtraBytes());
section.add("privsigningkey", exportSecret(identity.getPrivateKey().getPrivateSigningKey()));

View File

@ -70,6 +70,9 @@ public class WifImporter {
section.get("payloadlengthextrabytes", long.class),
Pubkey.Feature.bitfield(features)
);
if (section.containsKey("chan")) {
address.setChan(section.get("chan", boolean.class));
}
address.setAlias(section.get("label"));
identities.add(address);
}

View File

@ -17,6 +17,7 @@
package ch.dissem.bitmessage.wif;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.ports.*;
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography;
import org.junit.Before;
@ -80,9 +81,27 @@ public class WifExporterTest {
"noncetrialsperbyte = 320" + System.lineSeparator() +
"payloadlengthextrabytes = 14000" + System.lineSeparator() +
"privsigningkey = 5KU2gbe9u4rKJ8PHYb1rvwMnZnAJj4gtV5GLwoYckeYzygWUzB9" + System.lineSeparator() +
"privencryptionkey = 5KHd4c6cavd8xv4kzo3PwnVaYuBgEfg7voPQ5V97aZKgpYBXGck" + System.lineSeparator() + System.lineSeparator();
"privencryptionkey = 5KHd4c6cavd8xv4kzo3PwnVaYuBgEfg7voPQ5V97aZKgpYBXGck" + System.lineSeparator() +
System.lineSeparator();
importer = new WifImporter(ctx, expected);
exporter.addIdentity(importer.getIdentities().get(0));
assertEquals(expected, exporter.toString());
}
@Test
public void ensureChanIsAdded() throws Exception {
String expected = "[BM-2cW67GEKkHGonXKZLCzouLLxnLym3azS8r]" + System.lineSeparator() +
"label = general" + System.lineSeparator() +
"enabled = true" + System.lineSeparator() +
"decoy = false" + System.lineSeparator() +
"chan = true" + System.lineSeparator() +
"noncetrialsperbyte = 1000" + System.lineSeparator() +
"payloadlengthextrabytes = 1000" + System.lineSeparator() +
"privsigningkey = 5Jnbdwc4u4DG9ipJxYLznXSvemkRFueQJNHujAQamtDDoX3N1eQ" + System.lineSeparator() +
"privencryptionkey = 5JrDcFtQDv5ydcHRW6dfGUEvThoxCCLNEUaxQfy8LXXgTJzVAcq" + System.lineSeparator() +
System.lineSeparator();
BitmessageAddress chan = ctx.joinChan("general", "BM-2cW67GEKkHGonXKZLCzouLLxnLym3azS8r");
exporter.addIdentity(chan);
assertEquals(expected, exporter.toString());
}
}

View File

@ -25,9 +25,7 @@ import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class WifImporterTest {
@ -69,6 +67,7 @@ public class WifImporterTest {
assertNotNull("Private key", identity.getPrivateKey());
assertEquals(32, identity.getPrivateKey().getPrivateEncryptionKey().length);
assertEquals(32, identity.getPrivateKey().getPrivateSigningKey().length);
assertFalse(identity.isChan());
}
@Test
@ -98,4 +97,20 @@ public class WifImporterTest {
importer.importIdentity(identities.get(0));
verify(repo, times(1)).save(identities.get(0));
}
@Test
public void ensureChanIsImported() throws Exception {
importer = new WifImporter(ctx, "[BM-2cW67GEKkHGonXKZLCzouLLxnLym3azS8r]\n" +
"label = [chan] general\n" +
"enabled = true\n" +
"decoy = false\n" +
"chan = true\n" +
"noncetrialsperbyte = 1000\n" +
"payloadlengthextrabytes = 1000\n" +
"privsigningkey = 5Jnbdwc4u4DG9ipJxYLznXSvemkRFueQJNHujAQamtDDoX3N1eQ\n" +
"privencryptionkey = 5JrDcFtQDv5ydcHRW6dfGUEvThoxCCLNEUaxQfy8LXXgTJzVAcq\n");
assertEquals(1, importer.getIdentities().size());
BitmessageAddress chan = importer.getIdentities().get(0);
assertTrue(chan.isChan());
}
}