예제 #1
0
func TestKeyUpdate(t *testing.T) {

	priv, record, s := barChain()

	_, npub := libytc.DeterministicKey(2)

	NewKeyList := make(map[string]float64)
	NewKeyList[npub.Hash()] = 1.0

	k := NewKeyUpdate(record.Id, NewKeyList)
	k.Sign(priv)

	b := GFCEncoder{}.EncodeUpdate(k)
	j := GFCEncoder{}.DecodeUpdate(b)

	err := k.Verify(s)
	if err != nil {
		t.Fatal(err)
	}

	err = j.Verify(s)
	if err != nil {
		t.Fatal(err)
	}

	j.Apply(s)

	if s.State[record.Id].KeyList[npub.Hash()] != 1.0 {
		t.Fatal(s.State[record.Id])
	}
}
예제 #2
0
파일: nodes.go 프로젝트: Jonbeek/bytecoin
func OriginHostRecord() (private *ecdsa.PrivateKey, host *FileChainRecord) {
	host = new(FileChainRecord)
	host.Id = "Origin"
	host.Location = []string{"127.0.0.1"}
	host.Balance = 1e8
	private, public := libytc.DeterministicKey(0)
	host.KeyList = make(map[string]float64)
	host.KeyList[public.Hash()] = 1.0
	return
}
예제 #3
0
func TestNetworkPortSimple(t *testing.T) {
	t.Log("Make stuff")
	a := NewNetworkPort(NewServer(nil))
	b := NewNetworkPort(NewServer(nil))
	t.Log("Done making")

	a.s.event = make(chan string)

	c := make(chan error)
	go func() {
		c <- nil
		err := a.ListenNetwork("127.0.0.1:1777")
		if err != nil {
			t.Fatal(err)
		}
	}()

	t.Log("Before Block")
	<-c

	t.Log("Connecting")
	_, err := b.ConnectAddress("127.0.0.1:1777")
	if err != nil {
		t.Fatal(err)
	}

	t.Log("Connected")

	<-a.s.event

	t.Log("Recieved event")

	if len(a.s.ports) != 1 {
		t.Log(a.s.ports)
		t.Fatal("Failure to connect")
	}

	b.s.event = a.s.event
	a.s.event = nil

	priv, _ := libytc.DeterministicKey(0)
	_, h := libGFC.NewHost("destination")
	record := libGFC.NewHostUpdate(h)

	c = make(chan error)
	a.s.TransactionChannel <- TransactionError{record, nil, c}
	err = <-c
	if err != nil {
		t.Fatal(err)
	}
	o := <-b.s.event
	t.Log(o)

	u := libGFC.NewTransferUpdate("Origin", "Origin", 1)
	u.Sign(priv)

	if len(u.Signature.M) != 1 {
		t.Fatal("SignatureMap is not created")
	}

	c = make(chan error)
	a.s.TransactionChannel <- TransactionError{u, nil, c}
	err = <-c
	if err != nil {
		t.Fatal(err)
	}
	o = <-b.s.event
	t.Log(o)

	if len(b.s.SeenTransactions) != 2 {
		t.Fatal("Length is not 2, length is", len(b.s.SeenTransactions), b.s.SeenTransactions)
	}

}