Perform all serialization tests on a bytes.Buffer.

This commit is contained in:
Josh Rickmar 2014-03-14 10:22:37 -05:00 committed by Owain G. Ainsworth
parent 2fb710a02b
commit 03185be3cf

View file

@ -27,7 +27,6 @@ import (
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"math/big" "math/big"
"os"
"reflect" "reflect"
"testing" "testing"
) )
@ -60,22 +59,15 @@ func TestBtcAddressSerializer(t *testing.T) {
return return
} }
file, err := os.Create("btcaddress.bin") buf := new(bytes.Buffer)
if err != nil {
if _, err := addr.WriteTo(buf); err != nil {
t.Error(err.Error()) t.Error(err.Error())
return return
} }
defer file.Close()
if _, err := addr.WriteTo(file); err != nil {
t.Error(err.Error())
return
}
file.Seek(0, 0)
var readAddr btcAddress var readAddr btcAddress
_, err = readAddr.ReadFrom(file) _, err = readAddr.ReadFrom(buf)
if err != nil { if err != nil {
t.Error(err.Error()) t.Error(err.Error())
return return
@ -100,22 +92,15 @@ func TestScriptAddressSerializer(t *testing.T) {
return return
} }
file, err := os.Create("btcaddress.bin") buf := new(bytes.Buffer)
if err != nil {
if _, err := addr.WriteTo(buf); err != nil {
t.Error(err.Error()) t.Error(err.Error())
return return
} }
defer file.Close()
if _, err := addr.WriteTo(file); err != nil {
t.Error(err.Error())
return
}
file.Seek(0, 0)
var readAddr scriptAddress var readAddr scriptAddress
_, err = readAddr.ReadFrom(file) _, err = readAddr.ReadFrom(buf)
if err != nil { if err != nil {
t.Error(err.Error()) t.Error(err.Error())
return return
@ -135,22 +120,15 @@ func TestWalletCreationSerialization(t *testing.T) {
return return
} }
file, err := os.Create("newwallet.bin") buf := new(bytes.Buffer)
if err != nil {
t.Error(err.Error())
return
}
defer file.Close()
if _, err := w1.WriteTo(file); err != nil { if _, err := w1.WriteTo(buf); err != nil {
t.Error("Error writing new wallet: " + err.Error()) t.Error("Error writing new wallet: " + err.Error())
return return
} }
file.Seek(0, 0)
w2 := new(Wallet) w2 := new(Wallet)
_, err = w2.ReadFrom(file) _, err = w2.ReadFrom(buf)
if err != nil { if err != nil {
t.Error("Error reading newly written wallet: " + err.Error()) t.Error("Error reading newly written wallet: " + err.Error())
return return