Fixed tests & bugs, removed Ack payload type (a GenericPayload is now used)
- SystemTest don't work yet, sending messages seems broken - ProofOfWorkService needs some work, the current solution is a hack (and might be the reason above tests are broken)
This commit is contained in:
@ -22,19 +22,22 @@ import ch.dissem.bitmessage.entity.ObjectMessage;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.payload.ObjectType;
|
||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||
import ch.dissem.bitmessage.ports.*;
|
||||
import ch.dissem.bitmessage.utils.MessageMatchers;
|
||||
import ch.dissem.bitmessage.utils.Singleton;
|
||||
import ch.dissem.bitmessage.utils.TestUtils;
|
||||
import ch.dissem.bitmessage.utils.*;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ch.dissem.bitmessage.entity.payload.ObjectType.*;
|
||||
import static ch.dissem.bitmessage.utils.MessageMatchers.object;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.security;
|
||||
import static ch.dissem.bitmessage.utils.UnixTime.MINUTE;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.*;
|
||||
@ -59,9 +62,41 @@ public class BitmessageContextTest {
|
||||
.messageRepo(mock(MessageRepository.class))
|
||||
.networkHandler(mock(NetworkHandler.class))
|
||||
.nodeRegistry(mock(NodeRegistry.class))
|
||||
.powRepo(mock(ProofOfWorkRepository.class))
|
||||
.proofOfWorkEngine(mock(ProofOfWorkEngine.class))
|
||||
.powRepo(spy(new ProofOfWorkRepository() {
|
||||
Map<InventoryVector, Item> items = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getItem(byte[] initialHash) {
|
||||
return items.get(new InventoryVector(initialHash));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<byte[]> getItems() {
|
||||
List<byte[]> result = new LinkedList<>();
|
||||
for (InventoryVector iv : items.keySet()) {
|
||||
result.add(iv.getHash());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
||||
items.put(new InventoryVector(security().getInitialHash(object)), new Item(object, nonceTrialsPerByte, extraBytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeObject(byte[] initialHash) {
|
||||
items.remove(initialHash);
|
||||
}
|
||||
}))
|
||||
.proofOfWorkEngine(spy(new ProofOfWorkEngine() {
|
||||
@Override
|
||||
public void calculateNonce(byte[] initialHash, byte[] target, Callback callback) {
|
||||
callback.onNonceCalculated(initialHash, new byte[8]);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
TTL.msg(2 * MINUTE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -161,6 +196,7 @@ public class BitmessageContextTest {
|
||||
public void ensureMessageIsSent() throws Exception {
|
||||
ctx.send(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"), TestUtils.loadContact(),
|
||||
"Subject", "Message");
|
||||
assertEquals(1, ctx.internals().getProofOfWorkRepository().getItems().size());
|
||||
verify(ctx.internals().getProofOfWorkRepository(), timeout(10000).atLeastOnce())
|
||||
.putObject(object(MSG), eq(1000L), eq(1000L));
|
||||
verify(ctx.messages(), timeout(10000).atLeastOnce()).save(MessageMatchers.plaintext(Plaintext.Type.MSG));
|
||||
|
@ -66,6 +66,7 @@ public class DefaultMessageListenerTest extends TestBase {
|
||||
when(ctx.getMessageRepository()).thenReturn(messageRepo);
|
||||
when(ctx.getInventory()).thenReturn(inventory);
|
||||
when(ctx.getNetworkHandler()).thenReturn(networkHandler);
|
||||
when(ctx.getLabeler()).thenReturn(mock(Labeler.class));
|
||||
|
||||
listener = new DefaultMessageListener(ctx, mock(Labeler.class), mock(BitmessageContext.Listener.class));
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class EncryptionTest extends TestBase {
|
||||
PrivateKey privateKey = new PrivateKey(false, 1, 1000, 1000);
|
||||
CryptoBox cryptoBox = new CryptoBox(before, privateKey.getPubkey().getEncryptionKey());
|
||||
|
||||
GenericPayload after = GenericPayload.read(0, cryptoBox.decrypt(privateKey.getPrivateEncryptionKey()), 1, 100);
|
||||
GenericPayload after = GenericPayload.read(0, 1, cryptoBox.decrypt(privateKey.getPrivateEncryptionKey()), 100);
|
||||
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ public class ProofOfWorkServiceTest {
|
||||
when(ctx.getInventory()).thenReturn(inventory);
|
||||
when(ctx.getNetworkHandler()).thenReturn(networkHandler);
|
||||
when(ctx.getMessageRepository()).thenReturn(messageRepo);
|
||||
when(ctx.getLabeler()).thenReturn(mock(Labeler.class));
|
||||
|
||||
proofOfWorkService = new ProofOfWorkService();
|
||||
proofOfWorkService.setContext(ctx);
|
||||
|
@ -82,7 +82,7 @@ public class SerializationTest extends TestBase {
|
||||
.from(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||
.to(TestUtils.loadContact())
|
||||
.message("Subject", "Message")
|
||||
.ack("ack".getBytes())
|
||||
.ackData("ack".getBytes())
|
||||
.signature(new byte[0])
|
||||
.build();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
@ -72,7 +72,7 @@ public class TestUtils {
|
||||
|
||||
public static BitmessageAddress loadContact() throws IOException, DecryptionFailedException {
|
||||
BitmessageAddress address = new BitmessageAddress("BM-2cXxfcSetKnbHJX2Y85rSkaVpsdNUZ5q9h");
|
||||
ObjectMessage object = TestUtils.loadObjectMessage(4, "V4Pubkey.payload");
|
||||
ObjectMessage object = TestUtils.loadObjectMessage(3, "V4Pubkey.payload");
|
||||
object.decrypt(address.getPublicDecryptionKey());
|
||||
address.setPubkey((V4Pubkey) object.getPayload());
|
||||
return address;
|
||||
|
Reference in New Issue
Block a user