Beispiel #1
0
func TestService_Verification(t *testing.T) {
	local := onet.NewLocalTest()
	defer local.CloseAll()
	sbLength := 4
	_, el, genService := local.MakeHELS(sbLength, skipchainSID)
	service := genService.(*Service)

	elRoot := onet.NewRoster(el.List[0:3])
	sbRoot, err := makeGenesisRoster(service, elRoot)
	log.ErrFatal(err)

	log.Lvl1("Creating non-conforming skipBlock")
	sb := NewSkipBlock()
	sb.Roster = el
	sb.MaximumHeight = 1
	sb.BaseHeight = 1
	sb.ParentBlockID = sbRoot.Hash
	sb.VerifierID = VerifyShard
	_, err = service.ProposeSkipBlock(&ProposeSkipBlock{nil, sb})
	require.NotNil(t, err, "Shouldn't accept a non-confoirming skipblock")

	log.Lvl1("Creating skipblock with same Roster as root")
	sbInter, err := makeGenesisRosterArgs(service, elRoot, sbRoot.Hash, VerifyShard, 1, 1)
	log.ErrFatal(err)
	log.Lvl1("Creating skipblock with sub-Roster from root")
	elSub := onet.NewRoster(el.List[0:2])
	sbInter, err = makeGenesisRosterArgs(service, elSub, sbRoot.Hash, VerifyShard, 1, 1)
	log.ErrFatal(err)
	scsb := &SetChildrenSkipBlock{sbRoot.Hash, sbInter.Hash}
	service.SetChildrenSkipBlock(scsb)
}
Beispiel #2
0
// Servers contacts all servers in the entity-list and then makes checks
// on each pair. If server-descriptions are available, it will print them
// along with the IP-address of the server.
// In case a server doesn't reply in time or there is an error in the
// signature, an error is returned.
func Servers(g *config.Group) error {
	success := true
	// First check all servers individually
	for _, e := range g.Roster.List {
		desc := []string{"none", "none"}
		if d := g.GetDescription(e); d != "" {
			desc = []string{d, d}
		}
		el := onet.NewRoster([]*network.ServerIdentity{e})
		success = checkList(el, desc) == nil && success
	}
	if len(g.Roster.List) > 1 {
		// Then check pairs of servers
		for i, first := range g.Roster.List {
			for _, second := range g.Roster.List[i+1:] {
				log.Lvl3("Testing connection between", first, second)
				desc := []string{"none", "none"}
				if d1 := g.GetDescription(first); d1 != "" {
					desc = []string{d1, g.GetDescription(second)}
				}
				es := []*network.ServerIdentity{first, second}
				success = checkList(onet.NewRoster(es), desc) == nil && success
				es[0], es[1] = es[1], es[0]
				desc[0], desc[1] = desc[1], desc[0]
				success = checkList(onet.NewRoster(es), desc) == nil && success
			}
		}
	}

	if !success {
		return errors.New("At least one of the tests failed")
	}
	return nil
}
Beispiel #3
0
func TestClient_ProposeRoster(t *testing.T) {
	t.Skip("See https://github.com/dedis/cothority/issues/733")
	nbrHosts := 5
	l := onet.NewTCPTest()
	_, el, _ := l.GenTree(nbrHosts, true)
	defer l.CloseAll()

	c := NewTestClient(l)
	log.Lvl1("Creating root and control chain")
	_, inter, cerr := c.CreateRootControl(el, el, 1, 1, 1, VerifyNone)
	log.ErrFatal(cerr)
	el2 := onet.NewRoster(el.List[:nbrHosts-1])
	log.Lvl1("Proposing roster", el2)
	var sb1 *ProposedSkipBlockReply
	sb1, cerr = c.ProposeRoster(inter, el2)
	log.ErrFatal(cerr)
	log.Lvl1("Proposing same roster again")
	_, cerr = c.ProposeRoster(inter, el2)
	if cerr == nil {
		t.Fatal("Appending two Blocks to the same last block should fail")
	}
	log.Lvl1("Proposing following roster")
	sb2, cerr := c.ProposeRoster(sb1.Latest, el2)
	log.ErrFatal(cerr)
	if !sb2.Previous.Equal(sb1.Latest) {
		t.Fatal("New previous should be previous latest")
	}
	if !bytes.Equal(sb2.Previous.ForwardLink[0].Hash,
		sb2.Latest.Hash) {
		t.Fatal("second should point to third SkipBlock")
	}

	updates, cerr := c.GetUpdateChain(inter, inter.Hash)
	if len(updates.Update) != 3 {
		t.Fatal("Should now have three Blocks to go from Genesis to current, but have", len(updates.Update), inter, sb2)
	}
	if !updates.Update[2].Equal(sb2.Latest) {
		t.Fatal("Last block in update-chain should be last block added")
	}
	c.Close()
}
Beispiel #4
0
func TestService_SignBlock(t *testing.T) {
	// Testing whether we sign correctly the SkipBlocks
	local := onet.NewLocalTest()
	defer local.CloseAll()
	_, el, genService := local.MakeHELS(3, skipchainSID)
	service := genService.(*Service)

	sbRoot, err := makeGenesisRosterArgs(service, el, nil, VerifyNone, 1, 1)
	log.ErrFatal(err)
	el2 := onet.NewRoster(el.List[0:2])
	sb := NewSkipBlock()
	sb.Roster = el2
	psbr, err := service.ProposeSkipBlock(&ProposeSkipBlock{sbRoot.Hash, sb})
	log.ErrFatal(err)
	reply := psbr.(*ProposedSkipBlockReply)
	sbRoot = reply.Previous
	sbSecond := reply.Latest
	log.Lvl1("Verifying signatures")
	log.ErrFatal(sbRoot.VerifySignatures())
	log.ErrFatal(sbSecond.VerifySignatures())
}