You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

626 lines
17 KiB

  1. package statedb
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "io/ioutil"
  6. "math/big"
  7. "os"
  8. "strings"
  9. "testing"
  10. ethCommon "github.com/ethereum/go-ethereum/common"
  11. ethCrypto "github.com/ethereum/go-ethereum/crypto"
  12. "github.com/hermeznetwork/hermez-node/common"
  13. "github.com/hermeznetwork/hermez-node/log"
  14. "github.com/hermeznetwork/tracerr"
  15. "github.com/iden3/go-iden3-crypto/babyjub"
  16. "github.com/iden3/go-merkletree/db"
  17. "github.com/stretchr/testify/assert"
  18. "github.com/stretchr/testify/require"
  19. )
  20. func newAccount(t *testing.T, i int) *common.Account {
  21. var sk babyjub.PrivateKey
  22. _, err := hex.Decode(sk[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
  23. require.NoError(t, err)
  24. pk := sk.Public()
  25. key, err := ethCrypto.GenerateKey()
  26. require.NoError(t, err)
  27. address := ethCrypto.PubkeyToAddress(key.PublicKey)
  28. return &common.Account{
  29. Idx: common.Idx(256 + i),
  30. TokenID: common.TokenID(i),
  31. Nonce: common.Nonce(i),
  32. Balance: big.NewInt(1000),
  33. BJJ: pk.Compress(),
  34. EthAddr: address,
  35. }
  36. }
  37. func TestNewStateDBIntermediateState(t *testing.T) {
  38. dir, err := ioutil.TempDir("", "tmpdb")
  39. require.NoError(t, err)
  40. defer require.NoError(t, os.RemoveAll(dir))
  41. sdb, err := NewStateDB(dir, 128, TypeTxSelector, 0)
  42. require.NoError(t, err)
  43. // test values
  44. k0 := []byte("testkey0")
  45. k1 := []byte("testkey1")
  46. v0 := []byte("testvalue0")
  47. v1 := []byte("testvalue1")
  48. // store some data
  49. tx, err := sdb.db.DB().NewTx()
  50. require.NoError(t, err)
  51. err = tx.Put(k0, v0)
  52. require.NoError(t, err)
  53. err = tx.Commit()
  54. require.NoError(t, err)
  55. v, err := sdb.db.DB().Get(k0)
  56. require.NoError(t, err)
  57. assert.Equal(t, v0, v)
  58. // k0 not yet in last
  59. err = sdb.LastRead(func(sdb *Last) error {
  60. _, err := sdb.DB().Get(k0)
  61. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  62. return nil
  63. })
  64. require.NoError(t, err)
  65. // Close PebbleDB before creating a new StateDB
  66. sdb.Close()
  67. // call NewStateDB which should get the db at the last checkpoint state
  68. // executing a Reset (discarding the last 'testkey0'&'testvalue0' data)
  69. sdb, err = NewStateDB(dir, 128, TypeTxSelector, 0)
  70. require.NoError(t, err)
  71. v, err = sdb.db.DB().Get(k0)
  72. assert.NotNil(t, err)
  73. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  74. assert.Nil(t, v)
  75. // k0 not in last
  76. err = sdb.LastRead(func(sdb *Last) error {
  77. _, err := sdb.DB().Get(k0)
  78. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  79. return nil
  80. })
  81. require.NoError(t, err)
  82. // store the same data from the beginning that has ben lost since last NewStateDB
  83. tx, err = sdb.db.DB().NewTx()
  84. require.NoError(t, err)
  85. err = tx.Put(k0, v0)
  86. require.NoError(t, err)
  87. err = tx.Commit()
  88. require.NoError(t, err)
  89. v, err = sdb.db.DB().Get(k0)
  90. require.NoError(t, err)
  91. assert.Equal(t, v0, v)
  92. // k0 yet not in last
  93. err = sdb.LastRead(func(sdb *Last) error {
  94. _, err := sdb.DB().Get(k0)
  95. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  96. return nil
  97. })
  98. require.NoError(t, err)
  99. // make checkpoints with the current state
  100. bn, err := sdb.getCurrentBatch()
  101. require.NoError(t, err)
  102. assert.Equal(t, common.BatchNum(0), bn)
  103. err = sdb.db.MakeCheckpoint()
  104. require.NoError(t, err)
  105. bn, err = sdb.getCurrentBatch()
  106. require.NoError(t, err)
  107. assert.Equal(t, common.BatchNum(1), bn)
  108. // k0 in last
  109. err = sdb.LastRead(func(sdb *Last) error {
  110. v, err := sdb.DB().Get(k0)
  111. require.NoError(t, err)
  112. assert.Equal(t, v0, v)
  113. return nil
  114. })
  115. require.NoError(t, err)
  116. // write more data
  117. tx, err = sdb.db.DB().NewTx()
  118. require.NoError(t, err)
  119. err = tx.Put(k1, v1)
  120. require.NoError(t, err)
  121. err = tx.Put(k0, v1) // overwrite k0 with v1
  122. require.NoError(t, err)
  123. err = tx.Commit()
  124. require.NoError(t, err)
  125. v, err = sdb.db.DB().Get(k1)
  126. require.NoError(t, err)
  127. assert.Equal(t, v1, v)
  128. err = sdb.LastRead(func(sdb *Last) error {
  129. v, err := sdb.DB().Get(k0)
  130. require.NoError(t, err)
  131. assert.Equal(t, v0, v)
  132. return nil
  133. })
  134. require.NoError(t, err)
  135. // Close PebbleDB before creating a new StateDB
  136. sdb.Close()
  137. // call NewStateDB which should get the db at the last checkpoint state
  138. // executing a Reset (discarding the last 'testkey1'&'testvalue1' data)
  139. sdb, err = NewStateDB(dir, 128, TypeTxSelector, 0)
  140. require.NoError(t, err)
  141. bn, err = sdb.getCurrentBatch()
  142. require.NoError(t, err)
  143. assert.Equal(t, common.BatchNum(1), bn)
  144. // we closed the db without doing a checkpoint after overwriting k0, so
  145. // it's back to v0
  146. v, err = sdb.db.DB().Get(k0)
  147. require.NoError(t, err)
  148. assert.Equal(t, v0, v)
  149. v, err = sdb.db.DB().Get(k1)
  150. assert.NotNil(t, err)
  151. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  152. assert.Nil(t, v)
  153. }
  154. func TestStateDBWithoutMT(t *testing.T) {
  155. dir, err := ioutil.TempDir("", "tmpdb")
  156. require.NoError(t, err)
  157. defer require.NoError(t, os.RemoveAll(dir))
  158. sdb, err := NewStateDB(dir, 128, TypeTxSelector, 0)
  159. require.NoError(t, err)
  160. // create test accounts
  161. var accounts []*common.Account
  162. for i := 0; i < 4; i++ {
  163. accounts = append(accounts, newAccount(t, i))
  164. }
  165. // get non-existing account, expecting an error
  166. unexistingAccount := common.Idx(1)
  167. _, err = sdb.GetAccount(unexistingAccount)
  168. assert.NotNil(t, err)
  169. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  170. // add test accounts
  171. for i := 0; i < len(accounts); i++ {
  172. _, err = sdb.CreateAccount(accounts[i].Idx, accounts[i])
  173. require.NoError(t, err)
  174. }
  175. for i := 0; i < len(accounts); i++ {
  176. existingAccount := accounts[i].Idx
  177. accGetted, err := sdb.GetAccount(existingAccount)
  178. require.NoError(t, err)
  179. assert.Equal(t, accounts[i], accGetted)
  180. }
  181. // try already existing idx and get error
  182. existingAccount := common.Idx(256)
  183. _, err = sdb.GetAccount(existingAccount) // check that exist
  184. require.NoError(t, err)
  185. _, err = sdb.CreateAccount(common.Idx(256), accounts[1]) // check that can not be created twice
  186. assert.NotNil(t, err)
  187. assert.Equal(t, ErrAccountAlreadyExists, tracerr.Unwrap(err))
  188. // update accounts
  189. for i := 0; i < len(accounts); i++ {
  190. accounts[i].Nonce = accounts[i].Nonce + 1
  191. existingAccount = common.Idx(i)
  192. _, err = sdb.UpdateAccount(existingAccount, accounts[i])
  193. require.NoError(t, err)
  194. }
  195. _, err = sdb.MTGetProof(common.Idx(1))
  196. assert.NotNil(t, err)
  197. assert.Equal(t, ErrStateDBWithoutMT, tracerr.Unwrap(err))
  198. }
  199. func TestStateDBWithMT(t *testing.T) {
  200. dir, err := ioutil.TempDir("", "tmpdb")
  201. require.NoError(t, err)
  202. defer require.NoError(t, os.RemoveAll(dir))
  203. sdb, err := NewStateDB(dir, 128, TypeSynchronizer, 32)
  204. require.NoError(t, err)
  205. // create test accounts
  206. var accounts []*common.Account
  207. for i := 0; i < 20; i++ {
  208. accounts = append(accounts, newAccount(t, i))
  209. }
  210. // get non-existing account, expecting an error
  211. _, err = sdb.GetAccount(common.Idx(1))
  212. assert.NotNil(t, err)
  213. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  214. // add test accounts
  215. for i := 0; i < len(accounts); i++ {
  216. _, err = sdb.CreateAccount(accounts[i].Idx, accounts[i])
  217. require.NoError(t, err)
  218. }
  219. for i := 0; i < len(accounts); i++ {
  220. accGetted, err := sdb.GetAccount(accounts[i].Idx)
  221. require.NoError(t, err)
  222. assert.Equal(t, accounts[i], accGetted)
  223. }
  224. // try already existing idx and get error
  225. _, err = sdb.GetAccount(common.Idx(256)) // check that exist
  226. require.NoError(t, err)
  227. _, err = sdb.CreateAccount(common.Idx(256), accounts[1]) // check that can not be created twice
  228. assert.NotNil(t, err)
  229. assert.Equal(t, ErrAccountAlreadyExists, tracerr.Unwrap(err))
  230. _, err = sdb.MTGetProof(common.Idx(256))
  231. require.NoError(t, err)
  232. // update accounts
  233. for i := 0; i < len(accounts); i++ {
  234. accounts[i].Nonce = accounts[i].Nonce + 1
  235. _, err = sdb.UpdateAccount(accounts[i].Idx, accounts[i])
  236. require.NoError(t, err)
  237. }
  238. a, err := sdb.GetAccount(common.Idx(256)) // check that account value has been updated
  239. require.NoError(t, err)
  240. assert.Equal(t, accounts[0].Nonce, a.Nonce)
  241. }
  242. // TestCheckpoints performs almost the same test than kvdb/kvdb_test.go
  243. // TestCheckpoints, but over the StateDB
  244. func TestCheckpoints(t *testing.T) {
  245. dir, err := ioutil.TempDir("", "sdb")
  246. require.NoError(t, err)
  247. defer require.NoError(t, os.RemoveAll(dir))
  248. sdb, err := NewStateDB(dir, 128, TypeSynchronizer, 32)
  249. require.NoError(t, err)
  250. err = sdb.Reset(0)
  251. require.NoError(t, err)
  252. // create test accounts
  253. var accounts []*common.Account
  254. for i := 0; i < 10; i++ {
  255. accounts = append(accounts, newAccount(t, i))
  256. }
  257. // add test accounts
  258. for i := 0; i < len(accounts); i++ {
  259. _, err = sdb.CreateAccount(accounts[i].Idx, accounts[i])
  260. require.NoError(t, err)
  261. }
  262. // account doesn't exist in Last checkpoint
  263. _, err = sdb.LastGetAccount(accounts[0].Idx)
  264. assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err))
  265. // do checkpoints and check that currentBatch is correct
  266. err = sdb.MakeCheckpoint()
  267. require.NoError(t, err)
  268. cb, err := sdb.getCurrentBatch()
  269. require.NoError(t, err)
  270. assert.Equal(t, common.BatchNum(1), cb)
  271. // account exists in Last checkpoint
  272. accCur, err := sdb.GetAccount(accounts[0].Idx)
  273. require.NoError(t, err)
  274. accLast, err := sdb.LastGetAccount(accounts[0].Idx)
  275. require.NoError(t, err)
  276. assert.Equal(t, accounts[0], accLast)
  277. assert.Equal(t, accCur, accLast)
  278. for i := 1; i < 10; i++ {
  279. err = sdb.MakeCheckpoint()
  280. require.NoError(t, err)
  281. cb, err = sdb.getCurrentBatch()
  282. require.NoError(t, err)
  283. assert.Equal(t, common.BatchNum(i+1), cb)
  284. }
  285. // printCheckpoints(t, sdb.path)
  286. // reset checkpoint
  287. err = sdb.Reset(3)
  288. require.NoError(t, err)
  289. // check that reset can be repeated (as there exist the 'current' and
  290. // 'BatchNum3', from where the 'current' is a copy)
  291. err = sdb.Reset(3)
  292. require.NoError(t, err)
  293. // check that currentBatch is as expected after Reset
  294. cb, err = sdb.getCurrentBatch()
  295. require.NoError(t, err)
  296. assert.Equal(t, common.BatchNum(3), cb)
  297. // advance one checkpoint and check that currentBatch is fine
  298. err = sdb.MakeCheckpoint()
  299. require.NoError(t, err)
  300. cb, err = sdb.getCurrentBatch()
  301. require.NoError(t, err)
  302. assert.Equal(t, common.BatchNum(4), cb)
  303. err = sdb.db.DeleteCheckpoint(common.BatchNum(1))
  304. require.NoError(t, err)
  305. err = sdb.db.DeleteCheckpoint(common.BatchNum(2))
  306. require.NoError(t, err)
  307. err = sdb.db.DeleteCheckpoint(common.BatchNum(1)) // does not exist, should return err
  308. assert.NotNil(t, err)
  309. err = sdb.db.DeleteCheckpoint(common.BatchNum(2)) // does not exist, should return err
  310. assert.NotNil(t, err)
  311. // Create a LocalStateDB from the initial StateDB
  312. dirLocal, err := ioutil.TempDir("", "ldb")
  313. require.NoError(t, err)
  314. defer require.NoError(t, os.RemoveAll(dirLocal))
  315. ldb, err := NewLocalStateDB(dirLocal, 128, sdb, TypeBatchBuilder, 32)
  316. require.NoError(t, err)
  317. // get checkpoint 4 from sdb (StateDB) to ldb (LocalStateDB)
  318. err = ldb.Reset(4, true)
  319. require.NoError(t, err)
  320. // check that currentBatch is 4 after the Reset
  321. cb, err = ldb.getCurrentBatch()
  322. require.NoError(t, err)
  323. assert.Equal(t, common.BatchNum(4), cb)
  324. // advance one checkpoint in ldb
  325. err = ldb.MakeCheckpoint()
  326. require.NoError(t, err)
  327. cb, err = ldb.getCurrentBatch()
  328. require.NoError(t, err)
  329. assert.Equal(t, common.BatchNum(5), cb)
  330. // Create a 2nd LocalStateDB from the initial StateDB
  331. dirLocal2, err := ioutil.TempDir("", "ldb2")
  332. require.NoError(t, err)
  333. defer require.NoError(t, os.RemoveAll(dirLocal2))
  334. ldb2, err := NewLocalStateDB(dirLocal2, 128, sdb, TypeBatchBuilder, 32)
  335. require.NoError(t, err)
  336. // get checkpoint 4 from sdb (StateDB) to ldb (LocalStateDB)
  337. err = ldb2.Reset(4, true)
  338. require.NoError(t, err)
  339. // check that currentBatch is 4 after the Reset
  340. cb, err = ldb2.db.GetCurrentBatch()
  341. require.NoError(t, err)
  342. assert.Equal(t, common.BatchNum(4), cb)
  343. // advance one checkpoint in ldb2
  344. err = ldb2.db.MakeCheckpoint()
  345. require.NoError(t, err)
  346. cb, err = ldb2.db.GetCurrentBatch()
  347. require.NoError(t, err)
  348. assert.Equal(t, common.BatchNum(5), cb)
  349. debug := false
  350. if debug {
  351. printCheckpoints(t, sdb.path)
  352. printCheckpoints(t, ldb.path)
  353. printCheckpoints(t, ldb2.path)
  354. }
  355. }
  356. func TestStateDBGetAccounts(t *testing.T) {
  357. dir, err := ioutil.TempDir("", "tmpdb")
  358. require.NoError(t, err)
  359. sdb, err := NewStateDB(dir, 128, TypeTxSelector, 0)
  360. require.NoError(t, err)
  361. // create test accounts
  362. var accounts []common.Account
  363. for i := 0; i < 16; i++ {
  364. account := newAccount(t, i)
  365. accounts = append(accounts, *account)
  366. }
  367. // add test accounts
  368. for i := range accounts {
  369. _, err = sdb.CreateAccount(accounts[i].Idx, &accounts[i])
  370. require.NoError(t, err)
  371. }
  372. dbAccounts, err := sdb.TestGetAccounts()
  373. require.NoError(t, err)
  374. assert.Equal(t, accounts, dbAccounts)
  375. }
  376. func printCheckpoints(t *testing.T, path string) {
  377. files, err := ioutil.ReadDir(path)
  378. require.NoError(t, err)
  379. fmt.Println(path)
  380. for _, f := range files {
  381. fmt.Println(" " + f.Name())
  382. }
  383. }
  384. func bigFromStr(h string, u int) *big.Int {
  385. if u == 16 {
  386. h = strings.TrimPrefix(h, "0x")
  387. }
  388. b, ok := new(big.Int).SetString(h, u)
  389. if !ok {
  390. panic("bigFromStr err")
  391. }
  392. return b
  393. }
  394. func TestCheckAccountsTreeTestVectors(t *testing.T) {
  395. dir, err := ioutil.TempDir("", "tmpdb")
  396. require.NoError(t, err)
  397. defer require.NoError(t, os.RemoveAll(dir))
  398. sdb, err := NewStateDB(dir, 128, TypeSynchronizer, 32)
  399. require.NoError(t, err)
  400. ay0 := new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(253), nil), big.NewInt(1))
  401. // test value from js version (compatibility-canary)
  402. assert.Equal(t, "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", (hex.EncodeToString(ay0.Bytes())))
  403. bjjPoint0Comp := babyjub.PackSignY(true, ay0)
  404. bjj0 := babyjub.PublicKeyComp(bjjPoint0Comp)
  405. ay1 := bigFromStr("00", 16)
  406. bjjPoint1Comp := babyjub.PackSignY(false, ay1)
  407. bjj1 := babyjub.PublicKeyComp(bjjPoint1Comp)
  408. ay2 := bigFromStr("21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d7", 16)
  409. bjjPoint2Comp := babyjub.PackSignY(false, ay2)
  410. bjj2 := babyjub.PublicKeyComp(bjjPoint2Comp)
  411. ay3 := bigFromStr("0x10", 16) // 0x10=16
  412. bjjPoint3Comp := babyjub.PackSignY(false, ay3)
  413. require.NoError(t, err)
  414. bjj3 := babyjub.PublicKeyComp(bjjPoint3Comp)
  415. accounts := []*common.Account{
  416. {
  417. Idx: 1,
  418. TokenID: 0xFFFFFFFF,
  419. BJJ: bjj0,
  420. EthAddr: ethCommon.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
  421. Nonce: common.Nonce(0xFFFFFFFFFF),
  422. Balance: bigFromStr("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16),
  423. },
  424. {
  425. Idx: 100,
  426. TokenID: 0,
  427. BJJ: bjj1,
  428. EthAddr: ethCommon.HexToAddress("0x00"),
  429. Nonce: common.Nonce(0),
  430. Balance: bigFromStr("0", 10),
  431. },
  432. {
  433. Idx: 0xFFFFFFFFFFFF,
  434. TokenID: 3,
  435. BJJ: bjj2,
  436. EthAddr: ethCommon.HexToAddress("0xA3C88ac39A76789437AED31B9608da72e1bbfBF9"),
  437. Nonce: common.Nonce(129),
  438. Balance: bigFromStr("42000000000000000000", 10),
  439. },
  440. {
  441. Idx: 10000,
  442. TokenID: 1000,
  443. BJJ: bjj3,
  444. EthAddr: ethCommon.HexToAddress("0x64"),
  445. Nonce: common.Nonce(1900),
  446. Balance: bigFromStr("14000000000000000000", 10),
  447. },
  448. }
  449. for i := 0; i < len(accounts); i++ {
  450. _, err = accounts[i].HashValue()
  451. require.NoError(t, err)
  452. _, err = sdb.CreateAccount(accounts[i].Idx, accounts[i])
  453. if err != nil {
  454. log.Error(err)
  455. }
  456. require.NoError(t, err)
  457. }
  458. // root value generated by js version:
  459. assert.Equal(t, "17298264051379321456969039521810887093935433569451713402227686942080129181291", sdb.MT.Root().BigInt().String())
  460. }
  461. // TestListCheckpoints performs almost the same test than kvdb/kvdb_test.go
  462. // TestListCheckpoints, but over the StateDB
  463. func TestListCheckpoints(t *testing.T) {
  464. dir, err := ioutil.TempDir("", "tmpdb")
  465. require.NoError(t, err)
  466. defer require.NoError(t, os.RemoveAll(dir))
  467. sdb, err := NewStateDB(dir, 128, TypeSynchronizer, 32)
  468. require.NoError(t, err)
  469. numCheckpoints := 16
  470. // do checkpoints
  471. for i := 0; i < numCheckpoints; i++ {
  472. err = sdb.MakeCheckpoint()
  473. require.NoError(t, err)
  474. }
  475. list, err := sdb.db.ListCheckpoints()
  476. require.NoError(t, err)
  477. assert.Equal(t, numCheckpoints, len(list))
  478. assert.Equal(t, 1, list[0])
  479. assert.Equal(t, numCheckpoints, list[len(list)-1])
  480. numReset := 10
  481. err = sdb.Reset(common.BatchNum(numReset))
  482. require.NoError(t, err)
  483. list, err = sdb.db.ListCheckpoints()
  484. require.NoError(t, err)
  485. assert.Equal(t, numReset, len(list))
  486. assert.Equal(t, 1, list[0])
  487. assert.Equal(t, numReset, list[len(list)-1])
  488. }
  489. // TestDeleteOldCheckpoints performs almost the same test than
  490. // kvdb/kvdb_test.go TestDeleteOldCheckpoints, but over the StateDB
  491. func TestDeleteOldCheckpoints(t *testing.T) {
  492. dir, err := ioutil.TempDir("", "tmpdb")
  493. require.NoError(t, err)
  494. defer require.NoError(t, os.RemoveAll(dir))
  495. keep := 16
  496. sdb, err := NewStateDB(dir, keep, TypeSynchronizer, 32)
  497. require.NoError(t, err)
  498. numCheckpoints := 32
  499. // do checkpoints and check that we never have more than `keep`
  500. // checkpoints
  501. for i := 0; i < numCheckpoints; i++ {
  502. err = sdb.MakeCheckpoint()
  503. require.NoError(t, err)
  504. checkpoints, err := sdb.db.ListCheckpoints()
  505. require.NoError(t, err)
  506. assert.LessOrEqual(t, len(checkpoints), keep)
  507. }
  508. }
  509. func TestCurrentIdx(t *testing.T) {
  510. dir, err := ioutil.TempDir("", "tmpdb")
  511. require.NoError(t, err)
  512. defer require.NoError(t, os.RemoveAll(dir))
  513. keep := 16
  514. sdb, err := NewStateDB(dir, keep, TypeSynchronizer, 32)
  515. require.NoError(t, err)
  516. idx := sdb.CurrentIdx()
  517. assert.Equal(t, common.Idx(255), idx)
  518. sdb.Close()
  519. sdb, err = NewStateDB(dir, keep, TypeSynchronizer, 32)
  520. require.NoError(t, err)
  521. idx = sdb.CurrentIdx()
  522. assert.Equal(t, common.Idx(255), idx)
  523. err = sdb.MakeCheckpoint()
  524. require.NoError(t, err)
  525. idx = sdb.CurrentIdx()
  526. assert.Equal(t, common.Idx(255), idx)
  527. sdb.Close()
  528. sdb, err = NewStateDB(dir, keep, TypeSynchronizer, 32)
  529. require.NoError(t, err)
  530. idx = sdb.CurrentIdx()
  531. assert.Equal(t, common.Idx(255), idx)
  532. }