-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Increase bandwidth coverage * Cleanup * Remove whitespaces * Fix BandwidthSuggestGasLimit error message --------- Co-authored-by: libotony <[email protected]>
- Loading branch information
1 parent
c28bd36
commit 5d05048
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |