Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing (dot) create dot unit tests #1980

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6b61943
move build_spec_tests
edwardmack Nov 2, 2021
d12b7c2
added file
edwardmack Nov 2, 2021
2346cd9
move config_tests
edwardmack Nov 2, 2021
9ac48f4
move import_tests
edwardmack Nov 2, 2021
f10a4db
move node_tests
edwardmack Nov 2, 2021
8cafe33
move services_tests
edwardmack Nov 2, 2021
9042ce9
fix name
edwardmack Nov 2, 2021
1254342
move utils_tests
edwardmack Nov 2, 2021
035398c
Merge branch 'development' into ed/dot_tests_to_integration
edwardmack Nov 3, 2021
974b3b2
add build_spec unit tests
edwardmack Nov 3, 2021
e206c0c
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Nov 5, 2021
73d870a
refactor tests
edwardmack Nov 5, 2021
84321d7
lint
edwardmack Nov 5, 2021
28ce808
generate tests stubs
edwardmack Nov 6, 2021
6b3cd93
implement core config unit tests
edwardmack Nov 8, 2021
357dd19
add t.Parallel to tests
edwardmack Nov 8, 2021
b43f571
implement tests for import.go
edwardmack Nov 9, 2021
49c3add
add tests for node.go
edwardmack Nov 9, 2021
cecc641
implement service tests
edwardmack Nov 10, 2021
d5cee6c
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Nov 11, 2021
3cfdf93
implement services tests
edwardmack Nov 11, 2021
1c0afe5
implement utils tests
edwardmack Nov 12, 2021
0a95194
add to tests
edwardmack Nov 12, 2021
f1034a3
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Nov 12, 2021
8768a11
clean-up tests
edwardmack Nov 12, 2021
829a383
clean-up created test files
edwardmack Nov 12, 2021
5f871e3
address PR comments, clean-up
edwardmack Nov 12, 2021
487cc39
implement NewNodeB
edwardmack Nov 22, 2021
64f1d86
implement interface for new node
Nov 29, 2021
91dc01b
implement inteface functions for newNodeC
edwardmack Nov 29, 2021
3a952a6
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 1, 2021
65f9df8
add mocks for newNodeIface
edwardmack Dec 2, 2021
bc693cb
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 2, 2021
6f16011
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 3, 2021
800e0e9
implement mocks for tests
edwardmack Dec 3, 2021
89366c3
chore(deps): bump actions/setup-node from 2.4.1 to 2.5.0 (#2104)
dependabot[bot] Dec 6, 2021
2a18498
lint
edwardmack Dec 6, 2021
2842ba7
feat(wasmer/crypto): move sig verifier to crypto pkg (#2057)
1garo Dec 6, 2021
219ca79
remove testing NewNodeB
edwardmack Dec 6, 2021
e651076
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 6, 2021
d972258
change init keystore
edwardmack Dec 6, 2021
cdbe54c
remove newNodeC
edwardmack Dec 6, 2021
1d05a8d
remove gomocks.Any from tests
edwardmack Dec 7, 2021
eeb1115
remove naked return
edwardmack Dec 7, 2021
c84ca41
rename e to closeErr
edwardmack Dec 7, 2021
ecab259
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 8, 2021
2830f7b
WIP save
edwardmack Dec 8, 2021
1ef3897
fix Test_createGRANDPAService test to use mocks
edwardmack Dec 8, 2021
29d8975
fix failing tests
edwardmack Dec 9, 2021
2880f52
add to comment
edwardmack Dec 9, 2021
c71c873
Merge branch 'development' into ed/create_dot_unit_tests
edwardmack Dec 9, 2021
5665356
test commit
edwardmack Dec 9, 2021
f3936af
test commit
edwardmack Dec 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions dot/build_spec_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//go:build integration
// +build integration

// Copyright 2020 ChainSafe Systems (ON) Corp.
// This file is part of gossamer.
//
// The gossamer library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gossamer library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

package dot

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/stretchr/testify/require"
)

const genesisLocation = "../chain/gssmr/genesis.json"

func TestBuildFromGenesis_Integration(t *testing.T) {
file, err := genesis.CreateTestGenesisJSONFile(false)
defer os.Remove(file)
require.NoError(t, err)
bs, err := BuildFromGenesis(file, 0)

expectedChainType := "TESTCHAINTYPE"
expectedProperties := map[string]interface{}{
"ss58Format": 0.0,
"tokenDecimals": 0.0,
"tokenSymbol": "TEST",
}

bs.genesis.ChainType = expectedChainType
bs.genesis.Properties = expectedProperties

require.NoError(t, err)

// confirm human-readable fields
hr, err := bs.ToJSON()
require.NoError(t, err)
jGen := genesis.Genesis{}
err = json.Unmarshal(hr, &jGen)
require.NoError(t, err)
genesis.TestGenesis.Genesis = genesis.TestFieldsHR
require.Equal(t, genesis.TestGenesis.Genesis.Runtime, jGen.Genesis.Runtime)
require.Equal(t, expectedChainType, jGen.ChainType)
require.Equal(t, expectedProperties, jGen.Properties)

// confirm raw fields
raw, err := bs.ToJSONRaw()
require.NoError(t, err)
jGenRaw := genesis.Genesis{}
err = json.Unmarshal(raw, &jGenRaw)
require.NoError(t, err)
genesis.TestGenesis.Genesis = genesis.TestFieldsRaw
require.Equal(t, genesis.TestGenesis.Genesis.Raw, jGenRaw.Genesis.Raw)
require.Equal(t, expectedChainType, jGenRaw.ChainType)
require.Equal(t, expectedProperties, jGenRaw.Properties)
}

func TestBuildFromGenesis_WhenGenesisDoesNotExists(t *testing.T) {
bs, err := BuildFromGenesis("/not/exists/genesis.json", 0)
require.Nil(t, bs)
require.Error(t, err, os.ErrNotExist)
}

func TestWriteGenesisSpecFileWhenFileAlreadyExists(t *testing.T) {
f, err := ioutil.TempFile("", "existing file data")
require.NoError(t, err)
defer os.Remove(f.Name())

someBytes := []byte("Testing some bytes")
err = WriteGenesisSpecFile(someBytes, f.Name())

require.Error(t, err,
fmt.Sprintf("file %s already exists, rename to avoid overwritten", f.Name()))
}

func TestWriteGenesisSpecFile_Integration(t *testing.T) {
cfg := NewTestConfig(t)
cfg.Init.Genesis = genesisLocation

expected, err := genesis.NewGenesisFromJSONRaw(cfg.Init.Genesis)
require.NoError(t, err)

err = InitNode(cfg)
require.NoError(t, err)

bs, err := BuildFromGenesis(cfg.Init.Genesis, 0)
require.NoError(t, err)

data, err := bs.ToJSONRaw()
require.NoError(t, err)

tmpFiles := []string{
"/tmp/unique-raw-genesis.json",
"./unique-raw-genesis.json",
}

for _, tmpFile := range tmpFiles {
err = WriteGenesisSpecFile(data, tmpFile)
require.NoError(t, err)
require.FileExists(t, tmpFile)

defer os.Remove(tmpFile)

file, err := os.Open(tmpFile)
require.NoError(t, err)
defer file.Close()

genesisBytes, err := ioutil.ReadAll(file)
require.NoError(t, err)

gen := new(genesis.Genesis)
err = json.Unmarshal(genesisBytes, gen)
require.NoError(t, err)

require.Equal(t, expected.ChainType, gen.ChainType)
require.Equal(t, expected.Properties, gen.Properties)
}
}

func TestBuildFromDB_Integration(t *testing.T) {
// setup expected
cfg := NewTestConfig(t)
cfg.Init.Genesis = genesisLocation
expected, err := genesis.NewGenesisFromJSONRaw(cfg.Init.Genesis)
require.NoError(t, err)
// initialise node (initialise state database and load genesis data)
err = InitNode(cfg)
require.NoError(t, err)

bs, err := BuildFromDB(cfg.Global.BasePath)
require.NoError(t, err)
res, err := bs.ToJSON()
require.NoError(t, err)
jGen := genesis.Genesis{}
err = json.Unmarshal(res, &jGen)
require.NoError(t, err)

require.Equal(t, expected.Genesis.Raw["top"]["0x3a636f6465"], jGen.Genesis.Runtime["system"]["code"])
}
Loading