Skip to content
Snippets Groups Projects
  • Luca Moser's avatar
    57fb70b7
    Adds consensus integration test (#468) · 57fb70b7
    Luca Moser authored
    * 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
    
    * feat: Add first value transfer integration test
    
    * fix: fix wrong plugin name
    
    * :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
    
    * Add colored tokens test
    
    * Add value tangle test to github workflow
    
    * fix: Fix wrong function name in comments
    
    * refactor: Make testSnapshots disabled in default and minor tweaks
    
    * 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
    
    * adds snapshot type
    
    * Fix: finalized wasn't propagated when a branch was rejected
    
    * implements ReadFrom and WriteTo for Snapshot
    
    * read in snapshot file if snapshot path is defined
    
    * renames snapshot test file
    
    * WIP debugging concurrency bug of death
    
    * Feat: added more reliable fails in test case
    
    * Fix: fixes a race condition in solidification
    
    * Clean up test
    
    * adds assets volume to integration test containers
    
    * fixes some asserts
    
    * adds non-working conflict integration test
    
    * check transaction availability in partition
    
    * renames integration test
    
    * lower amount of peers
    
    * first passing version of consensus integration test
    
    * remove debug printlns
    
    * do all integration tests again
    
    * increases avg. network delay fcob rule, removes debug printlns
    
    * go mod tidy by Marie Kondō
    
    * renames incl. state. conflict to conflicting
    
    * go fmt tangle.go
    
    * go fmt tangle_test, goimports dapp.go
    
    * goimports again because the dog is sad
    
    * run consensus integration test on the CI
    
    * use explicit pumba version 0.7.2
    
    * pray to the CI gods for the test to pass
    
    * fix panic when tangle.Fork() is called
    
    * readd all tests again
    
    * reset integration framework paras
    
    * removes test snapshot plugin
    
    * get rid of test snapshot plugin
    
    * fixes wrong use of Println
    
    * removes random tool
    
    * removes duplicated value entry in GH CI workflows
    
    * xxx
    
    * wip
    
    * fixes integration test
    
    Co-authored-by: default avatarHans Moog <hm@mkjc.net>
    Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
    Co-authored-by: default avatarjonastheis <mail@jonastheis.de>
    Co-authored-by: default avatarcapossele <angelocapossele@gmail.com>
    Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
    Adds consensus integration test (#468)
    Luca Moser authored
    * 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
    
    * feat: Add first value transfer integration test
    
    * fix: fix wrong plugin name
    
    * :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
    
    * Add colored tokens test
    
    * Add value tangle test to github workflow
    
    * fix: Fix wrong function name in comments
    
    * refactor: Make testSnapshots disabled in default and minor tweaks
    
    * 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
    
    * adds snapshot type
    
    * Fix: finalized wasn't propagated when a branch was rejected
    
    * implements ReadFrom and WriteTo for Snapshot
    
    * read in snapshot file if snapshot path is defined
    
    * renames snapshot test file
    
    * WIP debugging concurrency bug of death
    
    * Feat: added more reliable fails in test case
    
    * Fix: fixes a race condition in solidification
    
    * Clean up test
    
    * adds assets volume to integration test containers
    
    * fixes some asserts
    
    * adds non-working conflict integration test
    
    * check transaction availability in partition
    
    * renames integration test
    
    * lower amount of peers
    
    * first passing version of consensus integration test
    
    * remove debug printlns
    
    * do all integration tests again
    
    * increases avg. network delay fcob rule, removes debug printlns
    
    * go mod tidy by Marie Kondō
    
    * renames incl. state. conflict to conflicting
    
    * go fmt tangle.go
    
    * go fmt tangle_test, goimports dapp.go
    
    * goimports again because the dog is sad
    
    * run consensus integration test on the CI
    
    * use explicit pumba version 0.7.2
    
    * pray to the CI gods for the test to pass
    
    * fix panic when tangle.Fork() is called
    
    * readd all tests again
    
    * reset integration framework paras
    
    * removes test snapshot plugin
    
    * get rid of test snapshot plugin
    
    * fixes wrong use of Println
    
    * removes random tool
    
    * removes duplicated value entry in GH CI workflows
    
    * xxx
    
    * wip
    
    * fixes integration test
    
    Co-authored-by: default avatarHans Moog <hm@mkjc.net>
    Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
    Co-authored-by: default avatarjonastheis <mail@jonastheis.de>
    Co-authored-by: default avatarcapossele <angelocapossele@gmail.com>
    Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
payload_handler.go 4.57 KiB
package dashboard

import (
	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
	valuepayload "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload"
	drngpayload "github.com/iotaledger/goshimmer/packages/binary/drng/payload"
	drngheader "github.com/iotaledger/goshimmer/packages/binary/drng/payload/header"
	cb "github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/payload"
	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
	"github.com/iotaledger/hive.go/marshalutil"
)

// BasicPayload contains content title and bytes
// It can be reused with different payload that only contains one field.
type BasicPayload struct {
	ContentTitle string `json:"content_title"`
	Bytes        []byte `json:"bytes"`
}

// DrngPayload contains the subtype of drng payload, instance Id
// and the subpayload
type DrngPayload struct {
	SubPayloadType byte        `json:"subpayload_type"`
	InstanceID     uint32      `json:"instance_id"`
	SubPayload     interface{} `json:"drngpayload"`
}

// DrngCollectiveBeaconPayload is the subpayload of DrngPayload.
type DrngCollectiveBeaconPayload struct {
	Round   uint64 `json:"round"`
	PrevSig []byte `json:"prev_sig"`
	Sig     []byte `json:"sig"`
	Dpk     []byte `json:"dpk"`
}

// ValuePayload contains the transaction information
type ValuePayload struct {
	ID        string          `json:"payload_id"`
	ParentID0 string          `json:"parent_id_0"`
	ParentID1 string          `json:"parent_id_1"`
	TxID      string          `json:"tx_id"`
	Input     []InputContent  `json:"inputs"`
	Output    []OutputContent `json:"outputs"`
	Data      []byte          `json:"data"`
}

// InputContent contains the inputs of a transaction
type InputContent struct {
	Address string `json:"address"`
}

// OutputContent contains the outputs of a transaction
type OutputContent struct {
	Address  string    `json:"address"`
	Balances []Balance `json:"balance"`
}

// Balance contains the amount of specific color token
type Balance struct {
	Value int64  `json:"value"`
	Color string `json:"color"`
}

// ProcessPayload returns different structs regarding to the
// payload type.
func ProcessPayload(p payload.Payload) interface{} {
	switch p.Type() {
	case payload.DataType:
		// data payload
		return BasicPayload{
			ContentTitle: "Data",
			Bytes:        p.(*payload.Data).Data(),
		}
	case drngpayload.Type:
		// drng payload
		return processDrngPayload(p)
	case valuepayload.Type:
		return processValuePayload(p)
	default:
		// unknown payload
		return BasicPayload{
			ContentTitle: "Bytes",
			Bytes:        p.Bytes(),
		}
	}
}

// processDrngPayload handles the subtypes of Drng payload
func processDrngPayload(p payload.Payload) (dp DrngPayload) {
	var subpayload interface{}
	marshalUtil := marshalutil.New(p.Bytes())
	drngPayload, _ := drngpayload.Parse(marshalUtil)

	switch drngPayload.Header.PayloadType {
	case drngheader.TypeCollectiveBeacon:
		// collective beacon
		marshalUtil := marshalutil.New(p.Bytes())
		cbp, _ := cb.Parse(marshalUtil)
		subpayload = DrngCollectiveBeaconPayload{
			Round:   cbp.Round,
			PrevSig: cbp.PrevSignature,
			Sig:     cbp.Signature,
			Dpk:     cbp.Dpk,
		}
	default:
		subpayload = BasicPayload{
			ContentTitle: "bytes",
			Bytes:        drngPayload.Bytes(),
		}
	}
	return DrngPayload{
		SubPayloadType: drngPayload.Header.PayloadType,
		InstanceID:     drngPayload.Header.InstanceID,
		SubPayload:     subpayload,
	}
}

// processValuePayload handles Value payload
func processValuePayload(p payload.Payload) (vp ValuePayload) {
	marshalUtil := marshalutil.New(p.Bytes())
	v, _ := valuepayload.Parse(marshalUtil)

	var inputs []InputContent
	var outputs []OutputContent

	// TODO: retrieve balance
	v.Transaction().Inputs().ForEachAddress(func(currentAddress address.Address) bool {
		inputs = append(inputs, InputContent{Address: currentAddress.String()})
		return true
	})

	// Get outputs address and balance
	v.Transaction().Outputs().ForEach(func(address address.Address, balances []*balance.Balance) bool {
		var b []Balance
		for _, balance := range balances {
			b = append(b, Balance{
				Value: balance.Value,
				Color: balance.Color.String(),
			})
		}
		t := OutputContent{
			Address:  address.String(),
			Balances: b,
		}
		outputs = append(outputs, t)

		return true
	})

	return ValuePayload{
		ID:        v.ID().String(),
		ParentID0: v.TrunkID().String(),
		ParentID1: v.BranchID().String(),
		TxID:      v.Transaction().ID().String(),
		Input:     inputs,
		Output:    outputs,
		Data:      v.Transaction().GetDataPayload(),
	}
}