Beispiel #1
0
func TestClient_CreateData(t *testing.T) {
	l := onet.NewTCPTest()
	_, el, _ := l.GenTree(2, true)
	defer l.CloseAll()

	c := NewTestClient(l)
	_, inter, cerr := c.CreateRootControl(el, el, 1, 1, 1, VerifyNone)
	log.ErrFatal(cerr)
	td := &testData{1, "data-sc"}
	inter, data, cerr := c.CreateData(inter, 1, 1, VerifyNone, td)
	log.ErrFatal(cerr)
	if err := data.VerifySignatures(); err != nil {
		t.Fatal("Couldn't verify data-signature:", err)
	}
	if !bytes.Equal(data.ParentBlockID, inter.Hash) {
		t.Fatal("Data-chain doesn't point to intermediate-chain")
	}
	if !bytes.Equal(inter.ChildSL.Hash, data.Hash) {
		t.Fatal("Intermediate chain doesn't point to data-chain")
	}
	_, td1, err := network.UnmarshalRegisteredType(data.Data, network.DefaultConstructors(network.Suite))
	log.ErrFatal(err)
	if *td != td1.(testData) {
		t.Fatal("Stored data is not the same as initial data")
	}
}
Beispiel #2
0
// Copy returns a deep copy of the AccountList.
func (c *Config) Copy() *Config {
	b, err := network.MarshalRegisteredType(c)
	if err != nil {
		log.Error("Couldn't marshal AccountList:", err)
		return nil
	}
	_, msg, err := network.UnmarshalRegisteredType(b, network.DefaultConstructors(network.Suite))
	if err != nil {
		log.Error("Couldn't unmarshal AccountList:", err)
	}
	ilNew := msg.(Config)
	if len(ilNew.Data) == 0 {
		ilNew.Data = make(map[string]string)
	}
	return &ilNew
}