Ejemplo n.º 1
0
func init() {

	//call a helper method to load the core.yaml
	testutil.SetupCoreYAMLConfig("./../../../../../peer")

	// Initialization will get a handle to the ledger at the specified path
	// Note, if subledgers are supported in the future,
	// the various ledgers could be created/managed at this level
	os.RemoveAll(ledgerPath)
	ledgerConf := kvledger.NewConf(ledgerPath, 0)
	var err error
	finalLedger, err = kvledger.NewKVLedger(ledgerConf)
	if err != nil {
		panic(fmt.Errorf("Error in NewKVLedger(): %s", err))
	}
	app = example.ConstructAppInstance(finalLedger)
	committer = example.ConstructCommitter(finalLedger)
	consenter = example.ConstructConsenter()
}
Ejemplo n.º 2
0
func TestKVLedgerBlockStorage(t *testing.T) {
	conf := kvledger.NewConf("/tmp/tests/ledger/", 0)
	defer os.RemoveAll("/tmp/tests/ledger/")

	ledger, _ := kvledger.NewKVLedger(conf)
	defer ledger.Close()

	committer := NewLedgerCommitter(ledger)

	height, err := committer.LedgerHeight()
	assert.Equal(t, uint64(0), height)
	assert.NoError(t, err)

	bcInfo, _ := ledger.GetBlockchainInfo()
	testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
		Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil})

	simulator, _ := ledger.NewTxSimulator()
	simulator.SetState("ns1", "key1", []byte("value1"))
	simulator.SetState("ns1", "key2", []byte("value2"))
	simulator.SetState("ns1", "key3", []byte("value3"))
	simulator.Done()

	simRes, _ := simulator.GetTxSimulationResults()
	block1 := testutil.ConstructBlock(t, [][]byte{simRes}, true)

	err = committer.CommitBlock(block1)
	assert.NoError(t, err)

	height, err = committer.LedgerHeight()
	assert.Equal(t, uint64(1), height)
	assert.NoError(t, err)

	blocks := committer.GetBlocks([]uint64{1})
	assert.Equal(t, 1, len(blocks))
	assert.NoError(t, err)

	bcInfo, _ = ledger.GetBlockchainInfo()
	block1Hash := block1.Header.Hash()
	testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{
		Height: 1, CurrentBlockHash: block1Hash, PreviousBlockHash: []byte{}})
}
Ejemplo n.º 3
0
// Create new instance of KVLedger to be used for testing
func newCommitter(id int, basePath string) committer.Committer {
	conf := kvledger.NewConf(basePath+strconv.Itoa(id), 0)
	ledger, _ := kvledger.NewKVLedger(conf)
	return committer.NewLedgerCommitter(ledger)
}