Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed Mar 27, 2020
1 parent aee1bb4 commit be1ba80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 5 additions & 5 deletions blockchain/skipchain/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func (db *InMemoryDatabase) Atomic(tx func(Queries) error) error {
snapshot := db.clone()
db.Unlock()

err := tx(db)
err := tx(snapshot)
if err != nil {
db.Lock()
db.blocks = snapshot.blocks
db.Unlock()

return xerrors.Errorf("couldn't execute transaction: %v", err)
}

db.Lock()
db.blocks = snapshot.blocks
db.Unlock()

return nil
}

Expand Down
19 changes: 16 additions & 3 deletions ledger/byzcoin/txproc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func TestTxProcessor_Validate(t *testing.T) {
require.EqualError(t, err, "mismatch payload footprint '0xab' != '0xcd'")
}

func TestTxProcessor_Process(t *testing.T) {
proc := newTxProcessor()
proc.inventory = fakeInventory{page: &fakePage{index: 999}}

page, err := proc.process(&BlockPayload{})
require.NoError(t, err)
require.Equal(t, uint64(999), page.GetIndex())
}

func TestTxProcessor_Commit(t *testing.T) {
proc := newTxProcessor()
proc.inventory = fakeInventory{}
Expand All @@ -57,27 +66,31 @@ type fakePage struct {
footprint []byte
}

func (p fakePage) GetIndex() uint64 {
func (p *fakePage) GetIndex() uint64 {
return p.index
}

func (p fakePage) GetFootprint() []byte {
func (p *fakePage) GetFootprint() []byte {
return p.footprint
}

type fakeInventory struct {
inventory.Inventory
index uint64
footprint []byte
page *fakePage
err error
}

func (inv fakeInventory) GetStagingPage([]byte) inventory.Page {
if inv.page != nil {
return inv.page
}
return nil
}

func (inv fakeInventory) Stage(func(inventory.WritablePage) error) (inventory.Page, error) {
return fakePage{index: inv.index, footprint: inv.footprint}, inv.err
return &fakePage{index: inv.index, footprint: inv.footprint}, inv.err
}

func (inv fakeInventory) Commit([]byte) error {
Expand Down

0 comments on commit be1ba80

Please sign in to comment.