Skip to content

Commit

Permalink
Fix unittest bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi Xiao committed May 6, 2019
1 parent a3bb5b6 commit d83a8b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions blockproducer/chain_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package blockproducer

import (
"database/sql"

pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces"
"github.com/CovenantSQL/CovenantSQL/crypto/hash"
"github.com/CovenantSQL/CovenantSQL/proto"
Expand Down Expand Up @@ -171,6 +172,8 @@ func (c *Chain) queryAccountSQLChainProfiles(account proto.AccountAddress) (prof
if err != nil {
return
}

dbs = append(dbs, proto.DatabaseID(id))
}

return
Expand Down
14 changes: 9 additions & 5 deletions blockproducer/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func TestChain(t *testing.T) {
_, loaded = chain.immutable.loadOrStoreProviderObject(addr1, &types.ProviderProfile{})
So(loaded, ShouldBeFalse)
_, loaded = chain.immutable.loadOrStoreSQLChainObject(dbid1, &types.SQLChainProfile{
ID: dbid1,
Miners: []*types.MinerInfo{{Address: addr2}},
Users: []*types.SQLChainUser{{Address: addr1, Permission: &types.UserPermission{Role: types.Admin}}},
})
Expand All @@ -223,6 +224,9 @@ func TestChain(t *testing.T) {
TokenBalance: [types.SupportTokenNumber]uint64{100, 100, 100, 100, 100},
})
So(loaded, ShouldBeFalse)

sps := chain.immutable.compileChanges(nil)
_ = store(chain.storage, sps, nil)
chain.immutable.commit()

err = rpcService.QuerySQLChainProfile(
Expand Down Expand Up @@ -332,7 +336,7 @@ func TestChain(t *testing.T) {
So(err, ShouldBeNil)

// Create a sibling block from fork#0 and apply
_, bl, err = f0.produceBlock(2, begin.Add(2 * chain.period).UTC(), addr2, priv2)
_, bl, err = f0.produceBlock(2, begin.Add(2*chain.period).UTC(), addr2, priv2)
So(err, ShouldBeNil)
So(bl, ShouldNotBeNil)
err = chain.pushBlock(bl)
Expand All @@ -353,7 +357,7 @@ func TestChain(t *testing.T) {
err = chain.produceBlock(begin.Add(3 * chain.period).UTC())
So(err, ShouldBeNil)
// Create a sibling block from fork#1 and apply
f1, bl, err = f1.produceBlock(3, begin.Add(3 * chain.period).UTC(), addr2, priv2)
f1, bl, err = f1.produceBlock(3, begin.Add(3*chain.period).UTC(), addr2, priv2)
So(err, ShouldBeNil)
So(bl, ShouldNotBeNil)
f1.preview.commit()
Expand All @@ -366,7 +370,7 @@ func TestChain(t *testing.T) {
So(err, ShouldBeNil)
// Create a sibling block from fork#1 and apply
f1, bl, err = f1.produceBlock(
i, begin.Add(time.Duration(i) * chain.period).UTC(), addr2, priv2)
i, begin.Add(time.Duration(i)*chain.period).UTC(), addr2, priv2)
So(err, ShouldBeNil)
So(bl, ShouldNotBeNil)
f1.preview.commit()
Expand Down Expand Up @@ -403,13 +407,13 @@ func TestChain(t *testing.T) {
f1.addTx(t2)
f1.addTx(t3)
f1.addTx(t4)
f1, bl, err = f1.produceBlock(7, begin.Add(8 * chain.period).UTC(), addr2, priv2)
f1, bl, err = f1.produceBlock(7, begin.Add(8*chain.period).UTC(), addr2, priv2)
So(err, ShouldBeNil)
So(bl, ShouldNotBeNil)
f1.preview.commit()
err = chain.pushBlock(bl)
So(err, ShouldBeNil)
f1, bl, err = f1.produceBlock(8, begin.Add(9 * chain.period).UTC(), addr2, priv2)
f1, bl, err = f1.produceBlock(8, begin.Add(9*chain.period).UTC(), addr2, priv2)
So(err, ShouldBeNil)
So(bl, ShouldNotBeNil)
f1.preview.commit()
Expand Down
1 change: 0 additions & 1 deletion blockproducer/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ var (
`CREATE INDEX IF NOT EXISTS "idx__indexed_transactions__tx_type__timestamp" ON "indexed_transactions" ("tx_type", "timestamp" DESC);`,
`CREATE INDEX IF NOT EXISTS "idx__indexed_transactions__address__timestamp" ON "indexed_transactions" ("address", "timestamp" DESC);`,


`CREATE TABLE IF NOT EXISTS "indexed_shardChains" (
"account" TEXT,
"address" TEXT,
Expand Down

0 comments on commit d83a8b0

Please sign in to comment.