Skip to content
Snippets Groups Projects
Select Git revision
  • d177b4b41c8f938735ae227acfa412dcb40234f4
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

tipselector_test.go

Blame
  • tipselector_test.go 1.98 KiB
    package tipselector
    
    import (
    	"testing"
    	"time"
    
    	"github.com/iotaledger/hive.go/identity"
    	"github.com/stretchr/testify/assert"
    
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
    )
    
    func Test(t *testing.T) {
    	// create tip selector
    	tipSelector := New()
    
    	// check if first tips point to genesis
    	trunk1, branch1 := tipSelector.GetTips()
    	assert.Equal(t, message.EmptyId, trunk1)
    	assert.Equal(t, message.EmptyId, branch1)
    
    	// create a transaction and attach it
    	localIdentity1 := identity.GenerateLocalIdentity()
    	transaction1 := message.New(trunk1, branch1, localIdentity1.PublicKey(), time.Now(), 0, payload.NewData([]byte("testtransaction")), localIdentity1)
    	tipSelector.AddTip(transaction1)
    
    	// check if the tip shows up in the tip count
    	assert.Equal(t, 1, tipSelector.GetTipCount())
    
    	// check if next tips point to our first transaction
    	trunk2, branch2 := tipSelector.GetTips()
    	assert.Equal(t, transaction1.GetId(), trunk2)
    	assert.Equal(t, transaction1.GetId(), branch2)
    
    	// create a 2nd transaction and attach it
    	localIdentity2 := identity.GenerateLocalIdentity()
    	transaction2 := message.New(message.EmptyId, message.EmptyId, localIdentity2.PublicKey(), time.Now(), 0, payload.NewData([]byte("testtransaction")), localIdentity2)
    	tipSelector.AddTip(transaction2)
    
    	// check if the tip shows up in the tip count
    	assert.Equal(t, 2, tipSelector.GetTipCount())
    
    	// attach a transaction to our two tips
    	localIdentity3 := identity.GenerateLocalIdentity()
    	trunk3, branch3 := tipSelector.GetTips()
    	transaction3 := message.New(trunk3, branch3, localIdentity3.PublicKey(), time.Now(), 0, payload.NewData([]byte("testtransaction")), localIdentity3)
    	tipSelector.AddTip(transaction3)
    
    	// check if the tip shows replaces the current tips
    	trunk4, branch4 := tipSelector.GetTips()
    	assert.Equal(t, 1, tipSelector.GetTipCount())
    	assert.Equal(t, transaction3.GetId(), trunk4)
    	assert.Equal(t, transaction3.GetId(), branch4)
    }