package bisq.core.account.sign;

import bisq.common.crypto.Sig;
import bisq.common.util.Utilities;

import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils;

import com.google.common.base.Charsets;

import java.security.KeyPair;

import java.time.Instant;

import org.junit.Test;

import static org.junit.Assert.assertEquals;



import protobuf.PersistableNetworkPayload;

public class SignedWitnessTest {
    @Test
    public void testProtoRoundTrip() {
        ECKey arbitrator1Key = new ECKey();

        KeyPair peer1KeyPair = Sig.generateKeyPair();
        byte[] witnessOwner1PubKey = Sig.getPublicKeyBytes(peer1KeyPair.getPublic());

        byte[] witnessHash = Utils.sha256hash160(new byte[]{1});
        byte[] signature1 = arbitrator1Key.signMessage(Utilities.encodeToHex(witnessHash)).getBytes(Charsets.UTF_8);
        SignedWitness signedWitness = new SignedWitness(true, witnessHash, signature1, arbitrator1Key.getPubKey(), witnessOwner1PubKey, Instant.now().getEpochSecond(), 100);
        PersistableNetworkPayload proto = signedWitness.toProtoMessage();
        assertEquals(signedWitness, SignedWitness.fromProto(proto.getSignedWitness()));

    }

}

@@ -203,39 +203,8 @@
 s;%0A%0A
-import java.security.KeyPair;%0A%0A
 impo
@@ -300,54 +300,8 @@
 s;%0A%0A
-%0A%0Aimport protobuf.PersistableNetworkPayload;%0A%0A
 publ
@@ -427,62 +427,8 @@
 );%0A%0A
-        KeyPair peer1KeyPair = Sig.generateKeyPair();%0A
     
@@ -486,20 +486,29 @@
 tes(
-peer1
+Sig.generate
 KeyPair
+()
 .get
@@ -599,25 +599,36 @@
  byte%5B%5D 
-s
+witnessHashS
 ignature
 1 = arbi
@@ -619,17 +619,16 @@
 ignature
-1
  = arbit
@@ -790,17 +790,28 @@
 sh, 
-s
+witnessHashS
 ignature
 1, a
@@ -806,17 +806,16 @@
 ignature
-1
 , arbitr
@@ -899,82 +899,8 @@
 0);%0A
-        PersistableNetworkPayload proto = signedWitness.toProtoMessage();%0A
     
@@ -959,13 +959,38 @@
 oto(
-proto
+signedWitness.toProtoMessage()
 .get

make test nicer