Holy shit pointer crap was annoying! Serialize/deserialize works now.
Running "go test -v" will show the serialization and deserialization. Doing the rest of the wire stuff should be *much* faster since I figured everything out...
This commit is contained in:
1 parent
0c0900006d
commit
f51a5a6458
2 files changed
+119
-59
No files matched your search
+44
-4
@@ -7,11 +7,18 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
// "io/ioutil"
|
||||
// "io"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
//For debugging, writes to /dev/shm/
|
||||
//Maybe in the future do it if you do "go test -v"
|
||||
WRITE_FILE = false
|
||||
FILENAME = "/dev/shm/fundingRequest.raw"
|
||||
|
||||
//echo -n | openssl sha256 | openssl ripemd160
|
||||
ourRevocationHashBytes, _ = hex.DecodeString("9a2cbd088763db88dd8ba79e5726daa6aba4aa7e")
|
||||
ourRevocationHash [20]byte
|
||||
@@ -27,13 +34,15 @@ var (
|
||||
ourDeliveryPkScript, _ = hex.DecodeString("76a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac")
|
||||
|
||||
//echo -n | openssl sha256
|
||||
//This stuff gets reversed!!!
|
||||
shaHash1Bytes, _ = hex.DecodeString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
shaHash1, _ = wire.NewShaHash(shaHash1Bytes)
|
||||
outpoint1 = wire.NewOutPoint(shaHash1, 0)
|
||||
//echo | openssl sha256
|
||||
//This stuff gets reversed!!!
|
||||
shaHash2Bytes, _ = hex.DecodeString("01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b")
|
||||
shaHash2, _ = wire.NewShaHash(shaHash2Bytes)
|
||||
outpoint2 = wire.NewOutPoint(shaHash2, 0)
|
||||
outpoint2 = wire.NewOutPoint(shaHash2, 1)
|
||||
//create inputs from outpoint1 and outpoint2
|
||||
ourInputs = []*wire.TxIn{wire.NewTxIn(outpoint1, nil), wire.NewTxIn(outpoint2, nil)}
|
||||
|
||||
@@ -51,15 +60,46 @@ var (
|
||||
DeliveryPkScript: ourDeliveryPkScript,
|
||||
Inputs: ourInputs,
|
||||
}
|
||||
serializedString = "30000000000005f5e1000000000008f0d1809a2cbd088763db88dd8ba79e5726daa6aba4aa7e02f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
|
||||
)
|
||||
|
||||
func TestFundingRequestSerializeDeserialize(t *testing.T) {
|
||||
b := new(bytes.Buffer)
|
||||
err := createChannel.SerializeFundingRequest(b)
|
||||
if err != nil {
|
||||
fmt.Println("ERR")
|
||||
fmt.Println(err)
|
||||
t.Error("Serialization error")
|
||||
}
|
||||
t.Logf("ASDF: %x\n", b.Bytes())
|
||||
t.Logf("Serialized Funding Request: %x\n", b.Bytes())
|
||||
|
||||
//Check if we serialized correctly
|
||||
if serializedString != hex.EncodeToString(b.Bytes()) {
|
||||
t.Error("Serialization does not match expected")
|
||||
}
|
||||
|
||||
//So I can do: hexdump -C /dev/shm/fundingRequest.raw
|
||||
if WRITE_FILE {
|
||||
err = ioutil.WriteFile(FILENAME, b.Bytes(), 0644)
|
||||
if err != nil {
|
||||
t.Error("File write error")
|
||||
}
|
||||
}
|
||||
|
||||
//Test deserialization
|
||||
//Make a new buffer just to be clean
|
||||
c := new(bytes.Buffer)
|
||||
c.Write(b.Bytes())
|
||||
|
||||
var newChannel CreateChannel
|
||||
err = newChannel.DeserializeFundingRequest(c)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error("Deserialiation Error")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(newChannel, createChannel) {
|
||||
t.Error("Deserialization does not match!")
|
||||
}
|
||||
|
||||
t.Log(newChannel.String())
|
||||
}
|
||||
Reference in new issue
Block a user