Skip to content

Commit

Permalink
Merge pull request #2802 from oasislabs/pro-wh/bugfix/gasimport
Browse files Browse the repository at this point in the history
 go consensus: shorten gas import
  • Loading branch information
pro-wh authored Apr 1, 2020
2 parents 10c876d + dce4175 commit a72bc87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/2802.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go/consensus: Shorten gas import

Switch to more concise `FromUint64`.
4 changes: 1 addition & 3 deletions go/consensus/api/transaction/gas.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package transaction

import (
"math/big"

"github.com/oasislabs/oasis-core/go/common/errors"
"github.com/oasislabs/oasis-core/go/common/quantity"
)
Expand Down Expand Up @@ -35,7 +33,7 @@ func (f Fee) GasPrice() *quantity.Quantity {
}

var gasQ quantity.Quantity
if err := gasQ.FromBigInt(big.NewInt(int64(f.Gas))); err != nil {
if err := gasQ.FromUint64(uint64(f.Gas)); err != nil {
// Should never happen.
panic(err)
}
Expand Down
22 changes: 22 additions & 0 deletions go/consensus/api/transaction/gas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package transaction

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/oasislabs/oasis-core/go/common/quantity"
)

func TestFeeGasPrice(t *testing.T) {
// Test large Gas field.
var amt quantity.Quantity
require.NoError(t, amt.FromUint64(0x9000000000000000), "import amount")
gasPrice := Fee{
Amount: amt,
Gas: 0x9000000000000000,
}.GasPrice()
var referencePrice quantity.Quantity
require.NoError(t, referencePrice.FromUint64(1), "import reference price")
require.Zero(t, gasPrice.Cmp(&referencePrice), "price matches")
}

0 comments on commit a72bc87

Please sign in to comment.