Skip to content

Commit

Permalink
Increase bandwidth coverage (#727)
Browse files Browse the repository at this point in the history
* Increase bandwidth coverage

* Cleanup

* Remove whitespaces

* Fix BandwidthSuggestGasLimit error message

---------

Co-authored-by: libotony <[email protected]>
  • Loading branch information
MakisChristou and libotony authored Jun 26, 2024
1 parent c28bd36 commit 5d05048
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions cmd/thor/bandwidth/bandwidth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2024 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package bandwidth

import (
"crypto/rand"
"sync"
"testing"

"github.com/stretchr/testify/assert"
"github.com/vechain/thor/v2/block"
"github.com/vechain/thor/v2/thor"
)

func TestBandwidth(t *testing.T) {
bandwidth := Bandwidth{
value: 0,
lock: sync.Mutex{},
}

val := bandwidth.Value()

assert.Equal(t, uint64(0), val)
}

func GetMockHeader(t *testing.T) *block.Header {
var sig [65]byte
rand.Read(sig[:])

block := new(block.Builder).Build().WithSignature(sig[:])
h := block.Header()
return h
}

func TestBandwithUpdate(t *testing.T) {
bandwidth := Bandwidth{
value: 0,
lock: sync.Mutex{},
}

block := new(block.Builder).ParentID(thor.Bytes32{1}).Timestamp(1).GasLimit(100000).Beneficiary(thor.Address{1}).GasUsed(11234).TotalScore(1).StateRoot(thor.Bytes32{1}).ReceiptsRoot(thor.Bytes32{1}).Build()
header := block.Header()

bandwidth.Update(header, 1)
val := bandwidth.Value()

assert.Equal(t, uint64(11234000000000), val)
}

func TestBandwidthSuggestGasLimit(t *testing.T) {
bandwidth := Bandwidth{
value: 0,
lock: sync.Mutex{},
}

block := new(block.Builder).ParentID(thor.Bytes32{1}).Timestamp(1).GasLimit(100000).Beneficiary(thor.Address{1}).GasUsed(11234).TotalScore(1).StateRoot(thor.Bytes32{1}).ReceiptsRoot(thor.Bytes32{1}).Build()
header := block.Header()
bandwidth.Update(header, 1)
val := bandwidth.SuggestGasLimit()

assert.Equal(t, uint64(5617000000000), val)
}

0 comments on commit 5d05048

Please sign in to comment.