Skip to content

Commit

Permalink
Merge pull request #259 from dedis/move_testing_tools
Browse files Browse the repository at this point in the history
Move testing tools
  • Loading branch information
jbsv authored Aug 7, 2023
2 parents 94a2e36 + 8c416ff commit f932657
Show file tree
Hide file tree
Showing 110 changed files with 552 additions and 360 deletions.
52 changes: 52 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[*]
charset = utf-8
end_of_line = crlf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 100
tab_width = 4
ij_continuation_indent_size = 4
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides = 80
ij_wrap_on_typing = false

[.editorconfig]
ij_editorconfig_align_group_field_declarations = false
ij_editorconfig_space_after_colon = false
ij_editorconfig_space_after_comma = true
ij_editorconfig_space_before_colon = false
ij_editorconfig_space_before_comma = false
ij_editorconfig_spaces_around_assignment_operators = true

[*.go]
indent_style = tab
ij_smart_tabs = true
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true
ij_go_add_leading_space_to_comments = true
ij_go_add_parentheses_for_single_import = false
ij_go_call_parameters_new_line_after_left_paren = false
ij_go_call_parameters_right_paren_on_new_line = false
ij_go_call_parameters_wrap = normal
ij_go_fill_paragraph_width = 80
ij_go_group_stdlib_imports = false
ij_go_import_sorting = goimports
ij_go_keep_indents_on_empty_lines = false
ij_go_local_group_mode = project
ij_go_move_all_imports_in_one_declaration = true
ij_go_move_all_stdlib_imports_in_one_group = false
ij_go_remove_redundant_import_aliases = true
ij_go_run_go_fmt_on_reformat = true
ij_go_use_back_quotes_for_imports = false
ij_go_wrap_comp_lit = on_every_item
ij_go_wrap_comp_lit_newline_after_lbrace = true
ij_go_wrap_comp_lit_newline_before_rbrace = true
ij_go_wrap_func_params = on_every_item
ij_go_wrap_func_params_newline_after_lparen = true
ij_go_wrap_func_params_newline_before_rparen = true
ij_go_wrap_func_result = on_every_item
ij_go_wrap_func_result_newline_after_lparen = true
ij_go_wrap_func_result_newline_before_rparen = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea
cli/node/memcoin/memcoin
test/private.key
dkg/logs
Expand Down
2 changes: 1 addition & 1 deletion cli/node/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
urfave "github.com/urfave/cli/v2"
"go.dedis.ch/dela/cli"
"go.dedis.ch/dela/cli/ucli"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestCliBuilder_SetStartFlags(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cli/node/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/cli"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
"golang.org/x/xerrors"
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestSocketDaemon_Listen(t *testing.T) {
actions := &actionMap{}
actions.Set(fakeAction{
intFlags: map[string]int{"1": 1},
}) // id 0
}) // id 0
actions.Set(fakeAction{err: fake.GetError()}) // id 1

daemon := &socketDaemon{
Expand Down
8 changes: 5 additions & 3 deletions contracts/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
"go.dedis.ch/dela/core/txn"
"go.dedis.ch/dela/core/txn/signed"
"go.dedis.ch/dela/crypto/bls"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestExecute(t *testing.T) {
contract := NewContract([]byte{}, fakeAccess{err: fake.GetError()}, fakeStore{})
err := contract.Execute(fakeStore{}, makeStep(t, CmdArg, ""))
require.EqualError(t, err, "identity not authorized: fake.PublicKey ("+fake.GetError().Error()+")")
require.EqualError(t, err,
"identity not authorized: fake.PublicKey ("+fake.GetError().Error()+")")

contract = NewContract([]byte{}, fakeAccess{}, fakeStore{})
err = contract.Execute(fakeStore{}, makeStep(t, CmdArg, ""))
Expand Down Expand Up @@ -48,7 +49,8 @@ func TestGrant(t *testing.T) {
require.EqualError(t, err, "'access:grant_id' not found in tx arg")

err = contract.grant(fakeStore{}, makeStep(t, GrantIDArg, "x"))
require.EqualError(t, err, "failed to decode id from tx arg: encoding/hex: invalid byte: U+0078 'x'")
require.EqualError(t, err,
"failed to decode id from tx arg: encoding/hex: invalid byte: U+0078 'x'")

err = contract.grant(fakeStore{}, makeStep(t, GrantIDArg, "deadbeef"))
require.EqualError(t, err, "'access:grant_contract' not found in tx arg")
Expand Down
17 changes: 11 additions & 6 deletions contracts/access/controller/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.dedis.ch/dela/cli/node"
"go.dedis.ch/dela/core/execution/native"
"go.dedis.ch/dela/crypto/bls"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestAddAction_Execute(t *testing.T) {
Expand All @@ -22,19 +22,22 @@ func TestAddAction_Execute(t *testing.T) {

action := addAction{}
err := action.Execute(ctx)
require.EqualError(t, err, "failed to resolve native service: couldn't find dependency for '*native.Service'")
require.EqualError(t, err,
"failed to resolve native service: couldn't find dependency for '*native.Service'")

native := native.NewExecution()
ctx.Injector.Inject(native)

err = action.Execute(ctx)
require.EqualError(t, err, "failed to resolve access service: couldn't find dependency for 'access.Service'")
require.EqualError(t, err,
"failed to resolve access service: couldn't find dependency for 'access.Service'")

access := fakeAccess{}
ctx.Injector.Inject(&access)

err = action.Execute(ctx)
require.EqualError(t, err, "failed to resolve access store: couldn't find dependency for 'controller.accessStore'")
require.EqualError(t, err,
"failed to resolve access store: couldn't find dependency for 'controller.accessStore'")

store := fakeStore{}
ctx.Injector.Inject(&store)
Expand All @@ -52,12 +55,14 @@ func TestAddAction_Execute(t *testing.T) {
flags.strings["identity"] = []string{"a"}

err = action.Execute(ctx)
require.EqualError(t, err, "failed to parse identities: failed to decode pub key 'a': illegal base64 data at input byte 0")
require.EqualError(t, err,
"failed to parse identities: failed to decode pub key 'a': illegal base64 data at input byte 0")

flags.strings["identity"] = []string{"AA=="}

err = action.Execute(ctx)
require.EqualError(t, err, "failed to parse identities: failed to unmarshal identity 'AA==': bn256.G2: not enough data")
require.EqualError(t, err,
"failed to parse identities: failed to unmarshal identity 'AA==': bn256.G2: not enough data")

signer := bls.NewSigner()
buf, err := signer.GetPublicKey().MarshalBinary()
Expand Down
14 changes: 10 additions & 4 deletions contracts/access/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.dedis.ch/dela/core/access"
"go.dedis.ch/dela/core/execution/native"
"go.dedis.ch/dela/core/store"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestSetCommands(t *testing.T) {
Expand All @@ -26,13 +26,15 @@ func TestOnStart(t *testing.T) {

injector := node.NewInjector()
err := ctrl.OnStart(node.FlagSet{}, injector)
require.EqualError(t, err, "failed to resolve access service: couldn't find dependency for 'access.Service'")
require.EqualError(t, err,
"failed to resolve access service: couldn't find dependency for 'access.Service'")

access := fakeAccess{}
injector.Inject(&access)

err = ctrl.OnStart(node.FlagSet{}, injector)
require.EqualError(t, err, "failed to resolve native service: couldn't find dependency for '*native.Service'")
require.EqualError(t, err,
"failed to resolve native service: couldn't find dependency for '*native.Service'")

native := native.NewExecution()
injector.Inject(native)
Expand Down Expand Up @@ -106,6 +108,10 @@ type fakeAccess struct {
err error
}

func (a fakeAccess) Grant(store store.Snapshot, creds access.Credential, idents ...access.Identity) error {
func (a fakeAccess) Grant(
store store.Snapshot,
creds access.Credential,
idents ...access.Identity,
) error {
return a.err
}
2 changes: 1 addition & 1 deletion contracts/access/controller/jstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde/json"
"go.dedis.ch/dela/testing/fake"
)

// constant holding the temporary dela directory name
Expand Down
5 changes: 3 additions & 2 deletions contracts/value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
"go.dedis.ch/dela/core/store"
"go.dedis.ch/dela/core/txn"
"go.dedis.ch/dela/core/txn/signed"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestExecute(t *testing.T) {
contract := NewContract([]byte{}, fakeAccess{err: fake.GetError()})

err := contract.Execute(fakeStore{}, makeStep(t))
require.EqualError(t, err, "identity not authorized: fake.PublicKey ("+fake.GetError().Error()+")")
require.EqualError(t, err,
"identity not authorized: fake.PublicKey ("+fake.GetError().Error()+")")

contract = NewContract([]byte{}, fakeAccess{})
err = contract.Execute(fakeStore{}, makeStep(t))
Expand Down
2 changes: 1 addition & 1 deletion core/access/darc/darc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"go.dedis.ch/dela/core/access"
"go.dedis.ch/dela/core/access/darc/types"
"go.dedis.ch/dela/crypto/bls"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/serde/json"
"go.dedis.ch/dela/testing/fake"
)

var testCtx = json.NewContext()
Expand Down
5 changes: 3 additions & 2 deletions core/access/darc/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/core/access/darc/types"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

const testValue = `{"Expressions":{"test":{"Identities":[{}],"Matches":[[0]]}}}`
Expand All @@ -30,7 +30,8 @@ func TestPermFormat_Encode(t *testing.T) {

perm = types.NewPermission(types.WithRule("test", fake.NewBadPublicKey()))
_, err = fmt.Encode(ctx, perm)
require.EqualError(t, err, fake.Err("failed to encode expression: failed to serialize identity"))
require.EqualError(t, err,
fake.Err("failed to encode expression: failed to serialize identity"))
}

func TestPermFormat_Decode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/access/darc/types/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/core/access"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion core/execution/native/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"go.dedis.ch/dela/core/execution"
"go.dedis.ch/dela/core/store"
"go.dedis.ch/dela/core/txn"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestService_Execute(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/ordering/cosipbft/authority/changeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions core/ordering/cosipbft/authority/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/dela/core/ordering/cosipbft/authority"
"go.dedis.ch/dela/crypto"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/mino"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

func TestChangeSetFormat_Encode(t *testing.T) {
Expand Down Expand Up @@ -99,7 +99,8 @@ func TestRosterFormat_Encode(t *testing.T) {
_, err = format.Encode(ctx, ro)
require.EqualError(t, err, fake.Err("couldn't marshal address"))

ro = authority.New([]mino.Address{fake.NewAddress(0)}, []crypto.PublicKey{fake.NewBadPublicKey()})
ro = authority.New([]mino.Address{fake.NewAddress(0)},
[]crypto.PublicKey{fake.NewBadPublicKey()})
_, err = format.Encode(ctx, ro)
require.EqualError(t, err, fake.Err("couldn't serialize public key"))
}
Expand Down
2 changes: 1 addition & 1 deletion core/ordering/cosipbft/authority/roster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/stretchr/testify/require"
"go.dedis.ch/dela/crypto/bls"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/mino"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion core/ordering/cosipbft/blockstore/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"go.dedis.ch/dela/core/store/kv"
"go.dedis.ch/dela/core/validation"
"go.dedis.ch/dela/core/validation/simple"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

func TestInDisk_Len(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/ordering/cosipbft/blockstore/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.dedis.ch/dela/core/ordering/cosipbft/authority"
"go.dedis.ch/dela/core/ordering/cosipbft/types"
"go.dedis.ch/dela/core/store/kv"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestCachedGenesis_Get(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions core/ordering/cosipbft/blockstore/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.dedis.ch/dela/core/ordering/cosipbft/types"
"go.dedis.ch/dela/core/store"
"go.dedis.ch/dela/core/validation/simple"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/testing/fake"
)

func TestInMemory_Len(t *testing.T) {
Expand Down Expand Up @@ -202,7 +202,8 @@ func makeLink(t *testing.T, from types.Digest, opts ...types.BlockOption) types.
to, err := types.NewBlock(simple.NewResult(nil), opts...)
require.NoError(t, err)

link, err := types.NewBlockLink(from, to, types.WithSignatures(fake.Signature{}, fake.Signature{}))
link, err := types.NewBlockLink(from, to,
types.WithSignatures(fake.Signature{}, fake.Signature{}))
require.NoError(t, err)

return link
Expand Down
5 changes: 3 additions & 2 deletions core/ordering/cosipbft/blocksync/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"go.dedis.ch/dela/core/txn/signed"
"go.dedis.ch/dela/core/validation/simple"
"go.dedis.ch/dela/crypto"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/mino"
"go.dedis.ch/dela/mino/minoch"
"go.dedis.ch/dela/testing/fake"
)

func TestDefaultSync_Basic(t *testing.T) {
Expand Down Expand Up @@ -210,7 +210,8 @@ func TestHandler_Stream(t *testing.T) {
require.EqualError(t, err, "reading genesis: missing genesis block")

recv = fake.NewReceiver(
fake.NewRecvMsg(fake.NewAddress(0), types.NewSyncMessage(fakeChain{err: fake.GetError()})),
fake.NewRecvMsg(fake.NewAddress(0),
types.NewSyncMessage(fakeChain{err: fake.GetError()})),
)

handler.genesis.Set(otypes.Genesis{})
Expand Down
2 changes: 1 addition & 1 deletion core/ordering/cosipbft/blocksync/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/dela/core/ordering/cosipbft/blocksync/types"
otypes "go.dedis.ch/dela/core/ordering/cosipbft/types"
"go.dedis.ch/dela/internal/testing/fake"
"go.dedis.ch/dela/serde"
"go.dedis.ch/dela/testing/fake"
)

func TestMsgFormat_Encode(t *testing.T) {
Expand Down
Loading

0 comments on commit f932657

Please sign in to comment.