Skip to content
Snippets Groups Projects
Unverified Commit ef1754f0 authored by Jonas Theis's avatar Jonas Theis Committed by GitHub
Browse files

Value tangle unit tests (#434)

* Feat: initial commit

* Feat: added setPreferred to TransactionMetadata

* Feat: added a Conflicting() method to the transactionMetadata

* Fix: fixed logic bug

* Feat: refactored fcob

* Refactor: refactored additional code

* Fix: fixed a bug in ForeachConsumers

* Refactor: cleaned up code

* Feat: implemented FCOB consensus into the valuetransfer dapp

* Refactor: refactored FCOB

* Docs: added some additional comments

* Docs: fixed comments

* add branch manager conflict test

* cleans failing test

* Refactor: commit before branch change

* Fix: fixed bug in AggregateBranches

* assert aggr. branch IDs

* expands branch conflict detection test

* add visualisation of branch graph of test

* Feat: added PayloadLiked Event

* Refactor: fixed some missing comments + added liked to marshal

* Feat: reworked the preferred and liked propagation

* Refactor: cleaned up some logic

* Refactor: simplified code

* Refactor: cleaned up more stuff :P

* Refactor: refactor

* Feat: moved test + refactored fcob

* adds more tests

* fixes liked state not getting updated correctly of conflict members

* adds additional liked/preferred propagation test

* Fix: fixed missing preferred propagation to aggregated branches

* Fix: fixed a few bugs in liked propagation

* adapt to new hive.go version

* upgrade hive.go

* Feat: started implementing a wallet

* Feat: extended wallet files

* remove weird test

* use mem db for tests

* more tests

* use store backed sequence

* add option to use in-memory database

* address review comments

* First tests for individual components of AttachPayloadSync

* Fix: fixed missing events in branchmanaer

* Feat: propagate changes from branch to transaction

* Add tests for checkTransactionOutputs

* Feat: started implementing confirmed propagation

* Fix: fixed unreachable code

* Add more tests

* Refactor: refactored some code according to wolfgangs review

* Refactor: cleaned up the code according to DRY

* Refactor: refactored according to wollac

* Refactor: refactored according to wollac

* Refactor: refactored according to wollac

* Refactor: refactored the code to make it more readable

* Refactor: added some doc comments + cleaned up some more code

* :white_check_mark: adds orderedMap unit tests

* :rotating_light: Fix linter warnings

* test: Add queue unit tests

* Add more tests

* :lipstick: Adjust imports order

* WIP more tests

* :white_check_mark: Add TestBookTransaction

* :white_check_mark: Update TestBookTransaction

* Add more tests

* :construction: WIP tests

* :white_check_mark: Add TestCalculateBranchOfTransaction

* :white_check_mark: Add TestMoveTransactionToBranch

* :white_check_mark: Add TestFork

* :white_check_mark: Add TestBookPayload

* Add test for checkPayloadSolidity

* :white_check_mark: Add TestSetTransactionPreferred

* Add more tests

* :white_check_mark: Fix Tangle test

* Feat: started implementing lucas test cases

* Feat: fixed some issued + further tests

* Feat: started adding invalid txs check

* Feat: added removal logic for invalid transactions

* Refactor: removed Println

* :white_check_mark: Add test for 2nd Reattachment

* :white_check_mark: Add aggregated branches test cases

* Feat: added a method to generate AggregatedBranchIDs

* :art: Use GenerateAggregatedBranchID in test

* Feat: refactored delete logic

* Fix: fixed broken test

* Feat: added final test cases for invalid txs / payloads

* :construction:

 WIP

* Value tangle concurrency tests (#451)

* Add simple concurrency test

* Add reverse and concurrent transaction and value object solidification tests and fix bug when value object was visited more than once

* Add some documentation to make tests easily understandable

* WIP propagation tests but fixed already couple of bugs

* Fix: fixed some bugs

* Feat: added propagation to inclusion states to tx and its outputs

* Feat: finished the propagation down to the tx and its outputs

* WIP propagation tests and fix bugs

* Feat: fixed some issues and introduced a Debugger

* Refactor: added a few comments

* Split massive test file into slightly more digestible chunks

* Clean up propagation tests

* Feat: fixed bugs

* Feat: enabled missing tests

* Add some documentation and missing checks for aggregated branches

* Clean up tangle tests

* Fix: finalized wasn't propagated when a branch was rejected

* WIP debugging concurrency bug of death

* Feat: added more reliable fails in test case

* Fix: fixes a race condition in solidification

* Clean up test

Co-authored-by: default avatarHans Moog <hm@mkjc.net>
Co-authored-by: default avatarLuca Moser <moser.luca@gmail.com>
Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
Co-authored-by: default avatarcapossele <angelocapossele@gmail.com>
Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
parent e64179a8
No related branches found
No related tags found
No related merge requests found
Showing
with 624 additions and 104 deletions
...@@ -354,6 +354,28 @@ func (branchManager *BranchManager) SetBranchFinalized(branchID BranchID) (modif ...@@ -354,6 +354,28 @@ func (branchManager *BranchManager) SetBranchFinalized(branchID BranchID) (modif
return branchManager.setBranchFinalized(branchManager.Branch(branchID)) return branchManager.setBranchFinalized(branchManager.Branch(branchID))
} }
// GenerateAggregatedBranchID generates an aggregated BranchID from the handed in BranchIDs.
func (branchManager *BranchManager) GenerateAggregatedBranchID(branchIDs ...BranchID) BranchID {
sort.Slice(branchIDs, func(i, j int) bool {
for k := 0; k < len(branchIDs[k]); k++ {
if branchIDs[i][k] < branchIDs[j][k] {
return true
} else if branchIDs[i][k] > branchIDs[j][k] {
return false
}
}
return false
})
marshalUtil := marshalutil.New(BranchIDLength * len(branchIDs))
for _, branchID := range branchIDs {
marshalUtil.WriteBytes(branchID.Bytes())
}
return blake2b.Sum256(marshalUtil.Bytes())
}
func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranch) (modified bool, err error) { func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranch) (modified bool, err error) {
defer cachedBranch.Release() defer cachedBranch.Release()
branch := cachedBranch.Unwrap() branch := cachedBranch.Unwrap()
...@@ -369,6 +391,11 @@ func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranc ...@@ -369,6 +391,11 @@ func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranc
branchManager.Events.BranchFinalized.Trigger(cachedBranch) branchManager.Events.BranchFinalized.Trigger(cachedBranch)
// propagate finalized to aggregated child branches
if err = branchManager.propagateFinalizedToAggregatedChildBranches(cachedBranch.Retain()); err != nil {
return
}
if !branch.Preferred() { if !branch.Preferred() {
branchManager.propagateRejectedToChildBranches(cachedBranch.Retain()) branchManager.propagateRejectedToChildBranches(cachedBranch.Retain())
...@@ -394,11 +421,62 @@ func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranc ...@@ -394,11 +421,62 @@ func (branchManager *BranchManager) setBranchFinalized(cachedBranch *CachedBranc
}) })
} }
// schedule confirmed checks of children
err = branchManager.propagateConfirmedToChildBranches(cachedBranch.Retain()) err = branchManager.propagateConfirmedToChildBranches(cachedBranch.Retain())
return return
} }
// propagateFinalizedToAggregatedChildBranches propagates the finalized flag to the aggregated child branches of the
// given branch. An aggregated branch is finalized if all of its parents are finalized.
func (branchManager *BranchManager) propagateFinalizedToAggregatedChildBranches(cachedBranch *CachedBranch) (err error) {
// initialize stack with the child branches of the given branch
propagationStack := list.New()
cachedBranch.Consume(func(branch *Branch) {
branchManager.ChildBranches(branch.ID()).Consume(func(childBranch *ChildBranch) {
propagationStack.PushBack(branchManager.Branch(childBranch.ChildID()))
})
})
// iterate through stack to propagate the changes to child branches
for propagationStack.Len() >= 1 {
stackElement := propagationStack.Front()
stackElement.Value.(*CachedBranch).Consume(func(branch *Branch) {
// abort if the branch is not aggregated
if !branch.IsAggregated() {
return
}
// abort if not all parents are confirmed
for _, parentBranchID := range branch.ParentBranches() {
cachedParentBranch := branchManager.Branch(parentBranchID)
if parentBranch := cachedParentBranch.Unwrap(); parentBranch == nil || !parentBranch.Finalized() {
cachedParentBranch.Release()
return
}
cachedParentBranch.Release()
}
// abort if the branch was finalized already
if !branch.setFinalized(true) {
return
}
// trigger events
branchManager.Events.BranchFinalized.Trigger(cachedBranch)
// schedule confirmed checks of children
branchManager.ChildBranches(branch.ID()).Consume(func(childBranch *ChildBranch) {
propagationStack.PushBack(branchManager.Branch(childBranch.childID))
})
})
propagationStack.Remove(stackElement)
}
return
}
func (branchManager *BranchManager) propagateRejectedToChildBranches(cachedBranch *CachedBranch) { func (branchManager *BranchManager) propagateRejectedToChildBranches(cachedBranch *CachedBranch) {
branchStack := list.New() branchStack := list.New()
branchStack.PushBack(cachedBranch) branchStack.PushBack(cachedBranch)
...@@ -459,9 +537,9 @@ func (branchManager *BranchManager) propagateConfirmedToChildBranches(cachedBran ...@@ -459,9 +537,9 @@ func (branchManager *BranchManager) propagateConfirmedToChildBranches(cachedBran
branchManager.Events.BranchConfirmed.Trigger(cachedBranch) branchManager.Events.BranchConfirmed.Trigger(cachedBranch)
// schedule confirmed checks of children // schedule confirmed checks of children
for _, cachedChildBranch := range branchManager.ChildBranches(branch.ID()) { branchManager.ChildBranches(branch.ID()).Consume(func(childBranch *ChildBranch) {
propagationStack.PushBack(cachedChildBranch) propagationStack.PushBack(branchManager.Branch(childBranch.childID))
} })
}) })
propagationStack.Remove(stackElement) propagationStack.Remove(stackElement)
} }
...@@ -839,24 +917,7 @@ func (branchManager *BranchManager) generateAggregatedBranchID(aggregatedBranche ...@@ -839,24 +917,7 @@ func (branchManager *BranchManager) generateAggregatedBranchID(aggregatedBranche
cachedBranch.Release() cachedBranch.Release()
} }
sort.Slice(branchIDs, func(i, j int) bool { return branchManager.GenerateAggregatedBranchID(branchIDs...)
for k := 0; k < len(branchIDs[k]); k++ {
if branchIDs[i][k] < branchIDs[j][k] {
return true
} else if branchIDs[i][k] > branchIDs[j][k] {
return false
}
}
return false
})
marshalUtil := marshalutil.New(BranchIDLength * len(branchIDs))
for _, branchID := range branchIDs {
marshalUtil.WriteBytes(branchID.Bytes())
}
return blake2b.Sum256(marshalUtil.Bytes())
} }
func (branchManager *BranchManager) collectClosestConflictAncestors(branch *Branch, closestConflictAncestors CachedBranches) (err error) { func (branchManager *BranchManager) collectClosestConflictAncestors(branch *Branch, closestConflictAncestors CachedBranches) (err error) {
......
...@@ -18,7 +18,7 @@ const ( ...@@ -18,7 +18,7 @@ const (
) )
var ( var (
osLeakDetectionOption = objectstorage.LeakDetectionEnabled(true, objectstorage.LeakDetectionOptions{ osLeakDetectionOption = objectstorage.LeakDetectionEnabled(false, objectstorage.LeakDetectionOptions{
MaxConsumersPerObject: 10, MaxConsumersPerObject: 10,
MaxConsumerHoldTime: 10 * time.Second, MaxConsumerHoldTime: 10 * time.Second,
}) })
......
package tangle package tangle
import ( import (
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/marshalutil" "github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage" "github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify" "github.com/iotaledger/hive.go/stringify"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
) )
// Attachment stores the information which transaction was attached by which payload. We need this to be able to perform // Attachment stores the information which transaction was attached by which payload. We need this to be able to perform
......
package tangle
import (
"testing"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/stretchr/testify/assert"
)
func TestAttachment(t *testing.T) {
transactionID := transaction.RandomID()
payloadID := payload.RandomID()
attachment := NewAttachment(transactionID, payloadID)
assert.Equal(t, transactionID, attachment.TransactionID())
assert.Equal(t, payloadID, attachment.PayloadID())
clonedAttachment, consumedBytes, err := AttachmentFromBytes(attachment.Bytes())
if err != nil {
panic(err)
}
assert.Equal(t, AttachmentLength, consumedBytes)
assert.Equal(t, transactionID, clonedAttachment.TransactionID())
assert.Equal(t, payloadID, clonedAttachment.PayloadID())
}
package tangle package tangle
import ( import (
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/marshalutil" "github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage" "github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify" "github.com/iotaledger/hive.go/stringify"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
) )
// ConsumerPartitionKeys defines the "layout" of the key. This enables prefix iterations in the objectstorage. // ConsumerPartitionKeys defines the "layout" of the key. This enables prefix iterations in the objectstorage.
......
package tangle
import (
"fmt"
"strings"
)
// Debugger represents a utility that allows us to print debug messages and function calls.
type Debugger struct {
aliases map[interface{}]string
enabled bool
indent int
}
// NewDebugger is the constructor of a debugger instance.
func NewDebugger() *Debugger {
return (&Debugger{}).ResetAliases()
}
// Enable sets the debugger to print the debug information.
func (debugger *Debugger) Enable() {
debugger.enabled = true
fmt.Println("[DEBUGGER::ENABLED]")
}
// Disable sets the debugger to not print any debug information.
func (debugger *Debugger) Disable() {
fmt.Println("[DEBUGGER::DISABLED]")
debugger.enabled = false
}
// ResetAliases removes any previously registered aliases. This can be useful if the same debugger instance is for
// example used in different tests or test cases.
func (debugger *Debugger) ResetAliases() *Debugger {
debugger.aliases = make(map[interface{}]string)
return debugger
}
// RegisterAlias registers a string representation for the given element. This can be used to create a string
// representation for things like ids in the form of byte slices.
func (debugger *Debugger) RegisterAlias(element interface{}, alias string) {
debugger.aliases[element] = alias
}
// FunctionCall prints debug information about a function call. It automatically indents all following debug outputs
// until Return() is called. The best way to use this is by starting a function call with a construct like:
//
// defer debugger.FunctionCall("myFunction", param1, param2).Return()
func (debugger *Debugger) FunctionCall(identifier string, params ...interface{}) *Debugger {
if !debugger.enabled {
return debugger
}
debugger.Print(identifier + "(" + debugger.paramsAsCommaSeparatedList(params...) + ") {")
debugger.indent++
return debugger
}
// Return prints debug information about a FunctionCall() the was finished. It reduces the indentation for consecutive
// debug outputs.
func (debugger *Debugger) Return() *Debugger {
if !debugger.enabled {
return debugger
}
debugger.indent--
debugger.Print("}")
return debugger
}
// Print prints an arbitrary debug message that can for example be used to print an information when a certain part of
// the code is executed.
func (debugger *Debugger) Print(identifier string, params ...interface{}) {
if !debugger.enabled {
return
}
if len(params) >= 1 {
debugger.print(identifier + " = " + debugger.paramsAsCommaSeparatedList(params...))
} else {
debugger.print(identifier)
}
}
// print is an internal utility function that actually prints the given string to stdout.
func (debugger *Debugger) print(stringToPrint string) {
fmt.Println("[DEBUGGER] " + strings.Repeat(" ", debugger.indent) + stringToPrint)
}
// paramsAsCommaSeparatedList creates a comma separated list of the given parameters.
func (debugger *Debugger) paramsAsCommaSeparatedList(params ...interface{}) string {
paramsAsStrings := make([]string, len(params))
for i, param := range params {
paramsAsStrings[i] = debugger.paramAsString(param)
}
return strings.Join(paramsAsStrings, ", ")
}
// paramAsString returns a string representation of an arbitrary parameter.
func (debugger *Debugger) paramAsString(param interface{}) string {
defer func() { recover() }()
if alias, aliasExists := debugger.aliases[param]; aliasExists {
return alias
}
return fmt.Sprint(param)
}
// debugger contains the default global debugger instance.
var debugger = NewDebugger()
package tangle package tangle
import ( import (
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/events"
) )
// Events is a container for the different kind of events of the Tangle. // Events is a container for the different kind of events of the Tangle.
...@@ -19,11 +18,18 @@ type Events struct { ...@@ -19,11 +18,18 @@ type Events struct {
PayloadDisliked *events.Event PayloadDisliked *events.Event
MissingPayloadReceived *events.Event MissingPayloadReceived *events.Event
PayloadMissing *events.Event PayloadMissing *events.Event
PayloadInvalid *events.Event
PayloadUnsolidifiable *events.Event PayloadUnsolidifiable *events.Event
// TransactionReceived gets triggered whenever a transaction was received for the first time (not solid yet). // TransactionReceived gets triggered whenever a transaction was received for the first time (not solid yet).
TransactionReceived *events.Event TransactionReceived *events.Event
// TransactionInvalid gets triggered whenever we receive an invalid transaction.
TransactionInvalid *events.Event
// TransactionSolid gets triggered whenever a transaction becomes solid for the first time.
TransactionSolid *events.Event
// TransactionBooked gets triggered whenever a transactions becomes solid and gets booked into a particular branch. // TransactionBooked gets triggered whenever a transactions becomes solid and gets booked into a particular branch.
TransactionBooked *events.Event TransactionBooked *events.Event
...@@ -74,8 +80,11 @@ func newEvents() *Events { ...@@ -74,8 +80,11 @@ func newEvents() *Events {
PayloadDisliked: events.NewEvent(cachedPayloadEvent), PayloadDisliked: events.NewEvent(cachedPayloadEvent),
MissingPayloadReceived: events.NewEvent(cachedPayloadEvent), MissingPayloadReceived: events.NewEvent(cachedPayloadEvent),
PayloadMissing: events.NewEvent(payloadIDEvent), PayloadMissing: events.NewEvent(payloadIDEvent),
PayloadInvalid: events.NewEvent(cachedPayloadErrorEvent),
PayloadUnsolidifiable: events.NewEvent(payloadIDEvent), PayloadUnsolidifiable: events.NewEvent(payloadIDEvent),
TransactionReceived: events.NewEvent(cachedTransactionAttachmentEvent), TransactionReceived: events.NewEvent(cachedTransactionAttachmentEvent),
TransactionInvalid: events.NewEvent(cachedTransactionErrorEvent),
TransactionSolid: events.NewEvent(cachedTransactionEvent),
TransactionBooked: events.NewEvent(transactionBookedEvent), TransactionBooked: events.NewEvent(transactionBookedEvent),
TransactionPreferred: events.NewEvent(cachedTransactionEvent), TransactionPreferred: events.NewEvent(cachedTransactionEvent),
TransactionUnpreferred: events.NewEvent(cachedTransactionEvent), TransactionUnpreferred: events.NewEvent(cachedTransactionEvent),
...@@ -100,6 +109,14 @@ func cachedPayloadEvent(handler interface{}, params ...interface{}) { ...@@ -100,6 +109,14 @@ func cachedPayloadEvent(handler interface{}, params ...interface{}) {
) )
} }
func cachedPayloadErrorEvent(handler interface{}, params ...interface{}) {
handler.(func(*payload.CachedPayload, *CachedPayloadMetadata, error))(
params[0].(*payload.CachedPayload).Retain(),
params[1].(*CachedPayloadMetadata).Retain(),
params[2].(error),
)
}
func transactionBookedEvent(handler interface{}, params ...interface{}) { func transactionBookedEvent(handler interface{}, params ...interface{}) {
handler.(func(*transaction.CachedTransaction, *CachedTransactionMetadata, bool))( handler.(func(*transaction.CachedTransaction, *CachedTransactionMetadata, bool))(
params[0].(*transaction.CachedTransaction).Retain(), params[0].(*transaction.CachedTransaction).Retain(),
...@@ -124,6 +141,14 @@ func cachedTransactionEvent(handler interface{}, params ...interface{}) { ...@@ -124,6 +141,14 @@ func cachedTransactionEvent(handler interface{}, params ...interface{}) {
) )
} }
func cachedTransactionErrorEvent(handler interface{}, params ...interface{}) {
handler.(func(*transaction.CachedTransaction, *CachedTransactionMetadata, error))(
params[0].(*transaction.CachedTransaction).Retain(),
params[1].(*CachedTransactionMetadata).Retain(),
params[2].(error),
)
}
func cachedTransactionAttachmentEvent(handler interface{}, params ...interface{}) { func cachedTransactionAttachmentEvent(handler interface{}, params ...interface{}) {
handler.(func(*transaction.CachedTransaction, *CachedTransactionMetadata, *CachedAttachment))( handler.(func(*transaction.CachedTransaction, *CachedTransactionMetadata, *CachedAttachment))(
params[0].(*transaction.CachedTransaction).Retain(), params[0].(*transaction.CachedTransaction).Retain(),
......
dapps/valuetransfers/packages/tangle/imgs/concurrency.png

15.8 KiB

dapps/valuetransfers/packages/tangle/imgs/reverse-transaction-solidification.png

20.6 KiB

dapps/valuetransfers/packages/tangle/imgs/reverse-valueobject-solidification.png

14 KiB

dapps/valuetransfers/packages/tangle/imgs/scenario1.png

184 KiB

dapps/valuetransfers/packages/tangle/imgs/scenario2.png

361 KiB

...@@ -3,11 +3,10 @@ package tangle ...@@ -3,11 +3,10 @@ package tangle
import ( import (
"time" "time"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
) )
// MissingOutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage. // MissingOutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage.
......
...@@ -3,10 +3,9 @@ package tangle ...@@ -3,10 +3,9 @@ package tangle
import ( import (
"time" "time"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/hive.go/marshalutil" "github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage" "github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
) )
// MissingPayload represents a payload that was referenced through branch or trunk but that is missing in our object // MissingPayload represents a payload that was referenced through branch or trunk but that is missing in our object
......
...@@ -3,10 +3,9 @@ package tangle ...@@ -3,10 +3,9 @@ package tangle
import ( import (
"time" "time"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/objectstorage"
) )
const ( const (
...@@ -26,7 +25,7 @@ const ( ...@@ -26,7 +25,7 @@ const (
) )
var ( var (
osLeakDetectionOption = objectstorage.LeakDetectionEnabled(true, objectstorage.LeakDetectionOptions{ osLeakDetectionOption = objectstorage.LeakDetectionEnabled(false, objectstorage.LeakDetectionOptions{
MaxConsumersPerObject: 20, MaxConsumersPerObject: 20,
MaxConsumerHoldTime: 10 * time.Second, MaxConsumerHoldTime: 10 * time.Second,
}) })
......
...@@ -4,14 +4,13 @@ import ( ...@@ -4,14 +4,13 @@ import (
"sync" "sync"
"time" "time"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify"
) )
// OutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage. // OutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage.
......
package tangle
import (
"testing"
"time"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/stretchr/testify/assert"
)
func TestNewOutput(t *testing.T) {
randomAddress := address.Random()
randomTransactionID := transaction.RandomID()
output := NewOutput(randomAddress, randomTransactionID, branchmanager.MasterBranchID, []*balance.Balance{
balance.New(balance.ColorIOTA, 1337),
})
assert.Equal(t, randomAddress, output.Address())
assert.Equal(t, randomTransactionID, output.TransactionID())
assert.Equal(t, false, output.Solid())
assert.Equal(t, time.Time{}, output.SolidificationTime())
assert.Equal(t, []*balance.Balance{
balance.New(balance.ColorIOTA, 1337),
}, output.Balances())
assert.Equal(t, true, output.setSolid(true))
assert.Equal(t, false, output.setSolid(true))
assert.Equal(t, true, output.Solid())
assert.NotEqual(t, time.Time{}, output.SolidificationTime())
clonedOutput, _, err := OutputFromBytes(output.Bytes())
if err != nil {
panic(err)
}
assert.Equal(t, output.Address(), clonedOutput.Address())
assert.Equal(t, output.TransactionID(), clonedOutput.TransactionID())
assert.Equal(t, output.Solid(), clonedOutput.Solid())
assert.Equal(t, output.SolidificationTime().Round(time.Second), clonedOutput.SolidificationTime().Round(time.Second))
assert.Equal(t, output.Balances(), clonedOutput.Balances())
}
package tangle package tangle
import ( import (
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/iotaledger/hive.go/marshalutil" "github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage" "github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
) )
// PayloadApprover is a database entity, that allows us to keep track of the "tangle structure" by encoding which // PayloadApprover is a database entity, that allows us to keep track of the "tangle structure" by encoding which
......
...@@ -4,9 +4,8 @@ import ( ...@@ -4,9 +4,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
"github.com/stretchr/testify/assert"
) )
func TestMarshalUnmarshal(t *testing.T) { func TestMarshalUnmarshal(t *testing.T) {
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment