Skip to content
Snippets Groups Projects
Select Git revision
  • e337f5b5165491184dc1acaf7e252334dadb2088
  • 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

go.mod

Blame
  • This project manages its dependencies using Go Modules. Learn more
    ledgerstate_test.go 2.25 KiB
    package ledgerstate
    
    import (
    	"fmt"
    	"strconv"
    	"testing"
    	"time"
    
    	"github.com/iotaledger/goshimmer/packages/objectstorage"
    )
    
    var (
    	iota               = NewColor("IOTA")
    	eth                = NewColor("ETH")
    	transferHash1      = NewTransferHash("TRANSFER1")
    	transferHash2      = NewTransferHash("TRANSFER2")
    	transferHash3      = NewTransferHash("TRANSFER3")
    	addressHash1       = NewAddressHash("ADDRESS1")
    	addressHash3       = NewAddressHash("ADDRESS3")
    	addressHash4       = NewAddressHash("ADDRESS4")
    	pendingReality     = NewRealityId("PENDING")
    	conflictingReality = NewRealityId("CONFLICTING")
    )
    
    func Benchmark(b *testing.B) {
    	ledgerState := NewLedgerState("testLedger").Prune().AddTransferOutput(
    		transferHash1, addressHash1, NewColoredBalance(eth, 1337),
    	)
    
    	b.ResetTimer()
    
    	for i := 0; i < b.N; i++ {
    		ledgerState.BookTransfer(NewTransfer(NewTransferHash(strconv.Itoa(i))).AddInput(
    			NewTransferOutputReference(transferHash1, addressHash1),
    		).AddOutput(
    			addressHash3, NewColoredBalance(eth, 1337),
    		))
    	}
    }
    
    func Test(t *testing.T) {
    	ledgerState := NewLedgerState("testLedger").Prune().AddTransferOutput(
    		transferHash1, addressHash1, NewColoredBalance(eth, 1337), NewColoredBalance(iota, 1338),
    	)
    
    	ledgerState.CreateReality(pendingReality)
    
    	transfer := NewTransfer(transferHash2).AddInput(
    		NewTransferOutputReference(transferHash1, addressHash1),
    	).AddOutput(
    		addressHash3, NewColoredBalance(iota, 338),
    	).AddOutput(
    		addressHash3, NewColoredBalance(eth, 337),
    	).AddOutput(
    		addressHash4, NewColoredBalance(iota, 1000),
    	).AddOutput(
    		addressHash4, NewColoredBalance(eth, 1000),
    	)
    
    	ledgerState.BookTransfer(transfer)
    	ledgerState.BookTransfer(NewTransfer(transferHash3).AddInput(
    		NewTransferOutputReference(transferHash1, addressHash1),
    	).AddOutput(
    		addressHash3, NewColoredBalance(iota, 338),
    	).AddOutput(
    		addressHash3, NewColoredBalance(eth, 337),
    	).AddOutput(
    		addressHash4, NewColoredBalance(iota, 1000),
    	).AddOutput(
    		addressHash4, NewColoredBalance(eth, 1000),
    	))
    
    	time.Sleep(1 * time.Second)
    
    	ledgerState.ForEachTransferOutput(func(object *objectstorage.CachedObject) bool {
    		object.Consume(func(object objectstorage.StorableObject) {
    			fmt.Println(object.(*TransferOutput))
    		})
    
    		return true
    	}, MAIN_REALITY_ID, addressHash1)
    }