Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Oct 2, 2020
1 parent b0a1bea commit a8d38b4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 354 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

EXCLUDE_LINT := should be.*UI
#TESTS := TestViewChange_Basic3\$$
TESTS := SecureDarc|TestDeferred_WrongSignature|TestViewChange_Basic|TestDeferred_DefaultExpireBlockIdx
#TESTS := SecureDarc|TestDeferred_WrongSignature|TestViewChange_Basic|TestDeferred_DefaultExpireBlockIdx
TESTS :=

Coding/bin/Makefile.base:
git clone https://github.com/dedis/Coding
Expand Down
2 changes: 2 additions & 0 deletions blscosi/protocol/sub_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func NewSubBlsCosi(n *onet.TreeNodeInstance, vf VerificationFn, suite *pairing.S
func (p *SubBlsCosi) Dispatch() error {
defer p.Done()

log.Printf("%s: has %s", p.ServerIdentity(), p.Tree().Dump())

// Send announcement to start sending signatures
if p.IsRoot() {
return p.dispatchRoot()
Expand Down
93 changes: 20 additions & 73 deletions byzcoin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,49 +118,29 @@ func TestClient_CreateTransaction(t *testing.T) {
}

func TestClient_GetProof(t *testing.T) {
l := onet.NewTCPTest(cothority.Suite)
servers, roster, _ := l.GenTree(3, true)
registerContracts(servers)
defer l.CloseAll()

// Initialise the genesis message and send it to the service.
signer := darc.NewSignerEd25519(nil, nil)
msg, err := DefaultGenesisMsg(CurrentVersion, roster, []string{"spawn:dummy"}, signer.Identity())
msg.BlockInterval = 100 * time.Millisecond
require.NoError(t, err)

// The darc inside it should be valid.
d := msg.GenesisDarc
require.Nil(t, d.Verify(true))

c, csr, err := NewLedger(msg, false)
require.NoError(t, err)

gac, err := c.GetAllByzCoinIDs(roster.List[1])
require.NoError(t, err)
require.Equal(t, 1, len(gac.IDs))
b := newBCTRun(t, nil)
defer b.CloseAll()

// Create a new transaction.
value := []byte{5, 6, 7, 8}
kind := "dummy"
tx, err := createOneClientTx(d.GetBaseID(), kind, value, signer)
tx, err := createOneClientTx(b.GenesisDarc.GetBaseID(), DummyContractName, value, b.Signer)
require.NoError(t, err)
atr, err := c.AddTransactionAndWait(tx, 10)
atr, err := b.Client.AddTransactionAndWait(tx, 10)
require.NoError(t, err)

// We should have a proof of our transaction in the skipchain.
newID := tx.Instructions[0].Hash()
p, err := c.GetProofAfter(newID, true, &atr.Proof.Latest)
p, err := b.Client.GetProofAfter(newID, true, &atr.Proof.Latest)
require.NoError(t, err)
require.Nil(t, p.Proof.Verify(csr.Skipblock.SkipChainID()))
require.Nil(t, p.Proof.Verify(b.Genesis.SkipChainID()))
require.Equal(t, 2, len(p.Proof.Links))
k, v0, _, _, err := p.Proof.KeyValue()
require.NoError(t, err)
require.Equal(t, k, newID)
require.Equal(t, value, v0)

// The proof should now be smaller as we learnt about the block
p, err = c.GetProofAfter(newID, false, &atr.Proof.Latest)
p, err = b.Client.GetProofAfter(newID, false, &atr.Proof.Latest)
require.NoError(t, err)
require.Equal(t, 1, len(p.Proof.Links))
}
Expand Down Expand Up @@ -198,41 +178,25 @@ func TestClient_GetProofCorrupted(t *testing.T) {
// Create a streaming client and add blocks in the background. The client
// should receive valid blocks.
func TestClient_Streaming(t *testing.T) {
l := onet.NewTCPTest(cothority.Suite)
servers, roster, _ := l.GenTree(3, true)
registerContracts(servers)
defer l.CloseAll()

// Initialise the genesis message and send it to the service.
signer := darc.NewSignerEd25519(nil, nil)
msg, err := DefaultGenesisMsg(CurrentVersion, roster, []string{"spawn:dummy"}, signer.Identity())
msg.BlockInterval = time.Second
require.NoError(t, err)

// The darc inside it should be valid.
d := msg.GenesisDarc
require.Nil(t, d.Verify(true))

c, csr, err := NewLedger(msg, false)
require.NoError(t, err)
b := newBCTRun(t, nil)
defer b.CloseAll()

n := 2
go func() {
time.Sleep(100 * time.Millisecond)
for i := 0; i < n; i++ {
value := []byte{5, 6, 7, 8}
kind := "dummy"
tx, err := createOneClientTxWithCounter(d.GetBaseID(), kind, value, signer, uint64(i)+1)
tx, err := createOneClientTxWithCounter(b.GenesisDarc.GetBaseID(), DummyContractName, value, b.Signer, uint64(i)+1)
// Need log.ErrFatal here, else it races with the rest of the code that
// uses 't'.
require.NoError(t, err)
_, err = c.AddTransaction(tx)
_, err = b.Client.AddTransaction(tx)
require.NoError(t, err)
}
}()

// Start collecting transactions
c1 := NewClientKeep(csr.Skipblock.Hash, *roster)
c1 := NewClientKeep(b.Genesis.Hash, *b.Roster)
var xMut sync.Mutex
var x int
done := make(chan bool)
Expand Down Expand Up @@ -263,48 +227,31 @@ func TestClient_Streaming(t *testing.T) {
}

go func() {
err = c1.StreamTransactions(cb)
err := c1.StreamTransactions(cb)
require.NoError(t, err)
}()
select {
case <-done:
case <-time.After(time.Duration(10) * msg.BlockInterval):
case <-time.After(time.Duration(10) * b.GenesisMessage.BlockInterval):
require.Fail(t, "should have got n transactions")
}
require.NoError(t, c1.Close())
}

func TestClient_NoPhantomSkipchain(t *testing.T) {
l := onet.NewTCPTest(cothority.Suite)
servers, roster, _ := l.GenTree(3, true)
registerContracts(servers)
defer l.CloseAll()

// Initialise the genesis message and send it to the service.
signer := darc.NewSignerEd25519(nil, nil)
msg, err := DefaultGenesisMsg(CurrentVersion, roster, []string{"spawn:dummy"}, signer.Identity())
msg.BlockInterval = 100 * time.Millisecond
require.NoError(t, err)

d := msg.GenesisDarc

c, _, err := NewLedger(msg, false)
require.NoError(t, err)

gac, err := c.GetAllByzCoinIDs(roster.List[0])
require.NoError(t, err)
require.Equal(t, 1, len(gac.IDs))
b := newBCTRun(t, nil)
defer b.CloseAll()

// Create a new transaction.
tx, err := createOneClientTx(d.GetBaseID(), "dummy", []byte{}, signer)
tx, err := createOneClientTx(b.GenesisDarc.GetBaseID(), DummyContractName,
[]byte{}, b.Signer)
require.NoError(t, err)
_, err = c.AddTransactionAndWait(tx, 10)
_, err = b.Client.AddTransactionAndWait(tx, 10)
require.NoError(t, err)

gac, err = c.GetAllByzCoinIDs(roster.List[0])
gac, err := b.Client.GetAllByzCoinIDs(b.Roster.List[0])
require.NoError(t, err)
require.Equal(t, 1, len(gac.IDs))
require.NoError(t, l.WaitDone(time.Second))
}

// Insure that the decoder will return an error if the reply
Expand Down
Loading

0 comments on commit a8d38b4

Please sign in to comment.