1
1
// Copyright 2021 ChainSafe Systems (ON)
2
2
// SPDX-License-Identifier: LGPL-3.0-only
3
3
4
+ //go:build integration
5
+ // +build integration
6
+
4
7
package dot
5
8
6
9
import (
7
10
"encoding/json"
11
+ "io/ioutil"
8
12
"math/big"
9
13
"os"
10
14
"path/filepath"
11
15
"testing"
12
16
17
+ "github.com/ChainSafe/gossamer/dot/state"
13
18
"github.com/ChainSafe/gossamer/dot/types"
19
+ "github.com/ChainSafe/gossamer/internal/log"
14
20
"github.com/ChainSafe/gossamer/lib/common"
15
21
"github.com/ChainSafe/gossamer/pkg/scale"
16
-
17
22
"github.com/stretchr/testify/require"
18
23
)
19
24
20
25
func setupStateFile (t * testing.T ) string {
21
- filename := "../lib/runtime/test_data/kusama/block1482002.out"
26
+ t . Helper ()
22
27
23
- data , err := os .ReadFile (filename )
28
+ const filename = "../lib/runtime/test_data/kusama/block1482002.out"
29
+
30
+ data , err := ioutil .ReadFile (filename )
24
31
require .NoError (t , err )
25
32
26
33
rpcPairs := make (map [string ]interface {})
@@ -31,16 +38,17 @@ func setupStateFile(t *testing.T) string {
31
38
bz , err := json .Marshal (pairs )
32
39
require .NoError (t , err )
33
40
34
- testDir := t .TempDir ()
35
- fp := filepath .Join (testDir , "state.json" )
36
- err = os .WriteFile (fp , bz , 0777 )
41
+ fp := filepath .Join (t .TempDir (), "state.json" )
42
+ err = ioutil .WriteFile (fp , bz , 0777 )
37
43
require .NoError (t , err )
38
44
39
45
return fp
40
46
}
41
47
42
48
func setupHeaderFile (t * testing.T ) string {
43
- headerStr := `{` +
49
+ t .Helper ()
50
+
51
+ const headerStr = `{` +
44
52
`"digest":{"logs":[` +
45
53
`"0x0642414245b501013c0000009659bd0f0000000070edad1c9064fff78cb18435223d8adaf5ea04c24b1a8766e3dc01eb03cc6a0c11b79793d4e31cc0990838229c44fed1669a7c7c79e1e6d0a96374d6496728069d1ef739e290497a0e3b728fa88fcbdd3a5504e0efde0242e7a806dd4fa9260c",` + //nolint:lll
46
54
`"0x054241424501019e7f28dddcf27c1e6b328d5694c368d5b2ec5dbe0e412ae1c98f88d53be4d8502fac571f3f19c9caaf281a673319241e0c5095a683ad34316204088a36a4bd86"` + //nolint:lll
@@ -49,20 +57,19 @@ func setupHeaderFile(t *testing.T) string {
49
57
`"number":"0x169d12",` +
50
58
`"parentHash":"0x3b45c9c22dcece75a30acc9c2968cb311e6b0557350f83b430f47559db786975",` +
51
59
`"stateRoot":"0x09f9ca28df0560c2291aa16b56e15e07d1e1927088f51356d522722aa90ca7cb"}`
52
- testDir := t .TempDir ()
53
- fp := filepath .Join (testDir , "header.json" )
54
- err := os .WriteFile (fp , []byte (headerStr ), 0777 )
60
+ fp := filepath .Join (t .TempDir (), "header.json" )
61
+ err := ioutil .WriteFile (fp , []byte (headerStr ), 0777 )
55
62
require .NoError (t , err )
56
63
return fp
57
64
}
58
65
59
66
func TestNewTrieFromPairs (t * testing.T ) {
60
67
fp := setupStateFile (t )
61
- tr , err := newTrieFromPairs (fp )
68
+ trie , err := newTrieFromPairs (fp )
62
69
require .NoError (t , err )
63
70
64
71
expectedRoot := common .MustHexToHash ("0x09f9ca28df0560c2291aa16b56e15e07d1e1927088f51356d522722aa90ca7cb" )
65
- require .Equal (t , expectedRoot , tr .MustHash ())
72
+ require .Equal (t , expectedRoot , trie .MustHash ())
66
73
}
67
74
68
75
func TestNewHeaderFromFile (t * testing.T ) {
@@ -74,7 +81,7 @@ func TestNewHeaderFromFile(t *testing.T) {
74
81
digest := types .NewDigest ()
75
82
err = scale .Unmarshal (digestBytes , & digest )
76
83
require .NoError (t , err )
77
- require .Equal (t , 2 , len ( digest .Types ) )
84
+ require .Len (t , digest .Types , 2 )
78
85
79
86
expected := & types.Header {
80
87
ParentHash : common .MustHexToHash ("0x3b45c9c22dcece75a30acc9c2968cb311e6b0557350f83b430f47559db786975" ),
@@ -88,7 +95,7 @@ func TestNewHeaderFromFile(t *testing.T) {
88
95
}
89
96
90
97
func TestImportState (t * testing.T ) {
91
- basepath := t .TempDir ()
98
+ basepath := os .TempDir ()
92
99
93
100
cfg := NewTestConfig (t )
94
101
require .NotNil (t , cfg )
@@ -104,7 +111,20 @@ func TestImportState(t *testing.T) {
104
111
stateFP := setupStateFile (t )
105
112
headerFP := setupHeaderFile (t )
106
113
107
- firstSlot : = uint64 (262493679 )
114
+ const firstSlot = uint64 (262493679 )
108
115
err = ImportState (basepath , stateFP , headerFP , firstSlot )
109
116
require .NoError (t , err )
117
+ // confirm data is imported into db
118
+ config := state.Config {
119
+ Path : basepath ,
120
+ LogLevel : log .Info ,
121
+ }
122
+ srv := state .NewService (config )
123
+ srv .SetupBase ()
124
+
125
+ lookupKey := []byte {98 , 108 , 111 , 99 , 107 , 104 , 100 , 114 , 88 , 127 , 109 , 161 , 191 , 167 , 26 , 103 , 95 , 16 , 223 , 160 ,
126
+ 246 , 62 , 223 , 207 , 22 , 142 , 142 , 206 , 151 , 235 , 95 , 82 , 106 , 175 , 14 , 138 , 142 , 130 , 219 , 63 }
127
+ data , err := srv .DB ().Get (lookupKey )
128
+ require .NoError (t , err )
129
+ require .NotNil (t , data )
110
130
}
0 commit comments