Add fixture options for icon consensus test
@@ -22,12 +22,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/icon-project/goloop/block"
+ "github.com/icon-project/goloop/common/db"
"github.com/icon-project/goloop/consensus"
"github.com/icon-project/goloop/icon/blockv0"
"github.com/icon-project/goloop/icon/blockv1"
"github.com/icon-project/goloop/icon/icconsensus"
"github.com/icon-project/goloop/module"
"github.com/icon-project/goloop/service"
+ "github.com/icon-project/goloop/service/platform/basic"
"github.com/icon-project/goloop/test"
)
@@ -54,6 +56,23 @@ func (plt *platform) MerkleLeaves() int64 {
return plt.mtCap
}
+func UseConfig(cf2 *test.FixtureConfig) test.FixtureOption {
+ return func(cf *test.FixtureConfig) *test.FixtureConfig {
+ return cf.Override(cf2)
+ }
+}
+
+func UseDB(dbase db.Database) test.FixtureOption {
+ return UseConfig(&test.FixtureConfig{ Dbase: dbase })
+}
+
+func UseMerkle(root []byte, leaves int64) test.FixtureOption {
+ return UseConfig(&test.FixtureConfig{
+ MerkleRoot: root,
+ MerkleLeaves: leaves,
+ })
+}
+
func UseBMForBlockV1(cf *test.FixtureConfig) *test.FixtureConfig {
return cf.Override(&test.FixtureConfig{
CVSD: func(bytes []byte) module.CommitVoteSet {
@@ -84,3 +103,24 @@ func UseBMForBlockV1(cf *test.FixtureConfig) *test.FixtureConfig {
})
}
+func UseCSForBlockV1(cf *test.FixtureConfig) *test.FixtureConfig {
+ return cf.Override(&test.FixtureConfig{
+ NewCS: func(ctx *test.FixtureContext) module.Consensus {
+ t := ctx.Config.T
+ iplt, ok := ctx.Platform.(MerkleInfo)
+ assert.True(t, ok)
+ wal := path.Join(ctx.Base, "wal")
+ wm := test.NewWAL()
+ cs, err := icconsensus.New(
+ ctx.C,
+ wal,
+ wm,
+ nil,
+ iplt.MerkleRoot(),
+ iplt.MerkleLeaves(),
+ )
+ assert.NoError(t, err)
+ return cs
+ },
+ })
+}
