Skip to content

Commit

Permalink
*: move all implementation-specific packages under internal directory
Browse files Browse the repository at this point in the history
Noone needs them, they are used only for tests and as examples.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Mar 1, 2024
1 parent f4029fc commit 4c215e7
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ jobs:

- name: Run simulation
run: |
cd ./simulation
cd ./internal/simulation
go run main.go
6 changes: 3 additions & 3 deletions dbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"time"

"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/block"
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/dbft/internal/block"
"github.com/nspcc-dev/dbft/internal/crypto"
"github.com/nspcc-dev/dbft/internal/payload"
"github.com/nspcc-dev/dbft/timer"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/dbft/internal/crypto"
"github.com/nspcc-dev/dbft/internal/payload"
"github.com/stretchr/testify/require"
)

Expand Down
6 changes: 3 additions & 3 deletions block/block.go → internal/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package block
import (
"bytes"
"encoding/gob"
"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/merkle"
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"
"github.com/nspcc-dev/dbft/internal/merkle"
)

type (
Expand Down
25 changes: 13 additions & 12 deletions block/block_test.go → internal/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
"encoding/binary"
"encoding/gob"
"errors"
"github.com/nspcc-dev/dbft"
"testing"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
crypto2 "github.com/nspcc-dev/dbft/internal/crypto"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNeoBlock_Setters(t *testing.T) {
b := new(neoBlock)

require.Equal(t, crypto.Uint256{}, b.Hash())
require.Equal(t, crypto2.Uint256{}, b.Hash())

txs := []dbft.Transaction[crypto.Uint256]{testTx(1), testTx(2)}
txs := []dbft.Transaction[crypto2.Uint256]{testTx(1), testTx(2)}
b.SetTransactions(txs)
assert.Equal(t, txs, b.Transactions())

Expand All @@ -29,14 +30,14 @@ func TestNeoBlock_Setters(t *testing.T) {
b.base.Version = 42
assert.EqualValues(t, 42, b.Version())

b.base.NextConsensus = crypto.Uint160{1}
assert.Equal(t, crypto.Uint160{1}, b.NextConsensus())
b.base.NextConsensus = crypto2.Uint160{1}
assert.Equal(t, crypto2.Uint160{1}, b.NextConsensus())

b.base.PrevHash = crypto.Uint256{3, 7}
assert.Equal(t, crypto.Uint256{3, 7}, b.PrevHash())
b.base.PrevHash = crypto2.Uint256{3, 7}
assert.Equal(t, crypto2.Uint256{3, 7}, b.PrevHash())

b.base.MerkleRoot = crypto.Uint256{13}
assert.Equal(t, crypto.Uint256{13}, b.MerkleRoot())
b.base.MerkleRoot = crypto2.Uint256{13}
assert.Equal(t, crypto2.Uint256{13}, b.MerkleRoot())

b.base.Timestamp = 1234
// 1234s -> 1234000000000ns
Expand All @@ -59,7 +60,7 @@ func TestNeoBlock_Setters(t *testing.T) {
})

t.Run("hash does not change after signature", func(t *testing.T) {
priv, pub := crypto.Generate(rand.Reader)
priv, pub := crypto2.Generate(rand.Reader)
require.NotNil(t, priv)
require.NotNil(t, pub)

Expand All @@ -85,7 +86,7 @@ func (t testKey) Sign([]byte) ([]byte, error) {

type testTx uint64

func (tx testTx) Hash() (h crypto.Uint256) {
func (tx testTx) Hash() (h crypto2.Uint256) {
binary.LittleEndian.PutUint64(h[:], uint64(tx))
return
}
3 changes: 2 additions & 1 deletion crypto/crypto.go → internal/crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package crypto

import (
"github.com/nspcc-dev/dbft"
"io"

"github.com/nspcc-dev/dbft"
)

type suiteType byte
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion crypto/ecdsa.go → internal/crypto/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"crypto/elliptic"
"crypto/sha256"
"errors"
"github.com/nspcc-dev/dbft"
"io"
"math/big"

"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/rfc6979"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion merkle/merkle_tree.go → internal/merkle/merkle_tree.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package merkle

import (
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/internal/crypto"
)

type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"testing"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/internal/crypto"
"github.com/stretchr/testify/require"
)

Expand Down
1 change: 1 addition & 0 deletions payload/change_view.go → internal/payload/change_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package payload

import (
"encoding/gob"

"github.com/nspcc-dev/dbft"
)

Expand Down
1 change: 1 addition & 0 deletions payload/commit.go → internal/payload/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package payload

import (
"encoding/gob"

"github.com/nspcc-dev/dbft"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package payload
import (
"bytes"
"encoding/gob"

"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"

"github.com/nspcc-dev/dbft/crypto"
"github.com/pkg/errors"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package payload

import (
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/internal/crypto"
)

// NewConsensusPayload returns minimal ConsensusPayload implementation.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions payload/message.go → internal/payload/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package payload
import (
"bytes"
"encoding/gob"
"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"
)

type (
Expand Down
25 changes: 13 additions & 12 deletions payload/message_test.go → internal/payload/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"crypto/rand"
"encoding/gob"
"github.com/nspcc-dev/dbft"
"testing"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
crypto2 "github.com/nspcc-dev/dbft/internal/crypto"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -16,7 +17,7 @@ func TestPayload_EncodeDecode(t *testing.T) {
m := NewConsensusPayload().(*Payload)
m.SetValidatorIndex(10)
m.SetHeight(77)
m.SetPrevHash(crypto.Uint256{1})
m.SetPrevHash(crypto2.Uint256{1})
m.SetVersion(8)
m.SetViewNumber(3)

Expand All @@ -25,7 +26,7 @@ func TestPayload_EncodeDecode(t *testing.T) {
m.SetPayload(&prepareRequest{
nonce: 123,
timestamp: 345,
transactionHashes: []crypto.Uint256{
transactionHashes: []crypto2.Uint256{
{1, 2, 3},
{5, 6, 7},
},
Expand All @@ -38,7 +39,7 @@ func TestPayload_EncodeDecode(t *testing.T) {
t.Run("PrepareResponse", func(t *testing.T) {
m.SetType(dbft.PrepareResponseType)
m.SetPayload(&prepareResponse{
preparationHash: crypto.Uint256{3},
preparationHash: crypto2.Uint256{3},
})

testEncodeDecode(t, m, new(Payload))
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestPayload_EncodeDecode(t *testing.T) {
prepareRequest: &prepareRequest{
nonce: 123,
timestamp: 345,
transactionHashes: []crypto.Uint256{
transactionHashes: []crypto2.Uint256{
{1, 2, 3},
{5, 6, 7},
},
Expand All @@ -111,22 +112,22 @@ func TestRecoveryMessage_NoPayloads(t *testing.T) {
m := NewConsensusPayload().(*Payload)
m.SetValidatorIndex(0)
m.SetHeight(77)
m.SetPrevHash(crypto.Uint256{1})
m.SetPrevHash(crypto2.Uint256{1})
m.SetVersion(8)
m.SetViewNumber(3)
m.SetPayload(&recoveryMessage{})

validators := make([]dbft.PublicKey, 1)
_, validators[0] = crypto.Generate(rand.Reader)
_, validators[0] = crypto2.Generate(rand.Reader)

rec := m.GetRecoveryMessage()
require.NotNil(t, rec)

var p dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160]
var p dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160]
require.NotPanics(t, func() { p = rec.GetPrepareRequest(p, validators, 0) })
require.Nil(t, p)

var ps []dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160]
var ps []dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160]
require.NotPanics(t, func() { ps = rec.GetPrepareResponses(p, validators) })
require.Len(t, ps, 0)

Expand Down Expand Up @@ -188,8 +189,8 @@ func TestPayload_Setters(t *testing.T) {
t.Run("RecoveryMessage", func(t *testing.T) {
r := NewRecoveryMessage()

r.SetPreparationHash(&crypto.Uint256{1, 2, 3})
require.Equal(t, &crypto.Uint256{1, 2, 3}, r.PreparationHash())
r.SetPreparationHash(&crypto2.Uint256{1, 2, 3})
require.Equal(t, &crypto2.Uint256{1, 2, 3}, r.PreparationHash())
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package payload

import (
"encoding/gob"
"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"
)

type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package payload

import (
"encoding/gob"
"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"
)

type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package payload
import (
"encoding/gob"
"errors"
"github.com/nspcc-dev/dbft"

"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/dbft/internal/crypto"
)

type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package payload

import (
"encoding/gob"

"github.com/nspcc-dev/dbft"
)

Expand Down
Loading

0 comments on commit 4c215e7

Please sign in to comment.