Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ tasks:
echo "Skipping $example"
continue
fi
# fee_estimate_query is flaky on a fresh local mirror node.
if [ "$dir_name" == "fee_estimate_query" ]; then
echo "Skipping $example (mirror node sync flake)"
continue
fi
if [ -d "$example" ]; then

pushd "$example" > /dev/null
Expand Down
29 changes: 29 additions & 0 deletions examples/fee_estimate_query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"time"

hiero "github.com/hiero-ledger/hiero-sdk-go/v2/sdk"
)
Expand Down Expand Up @@ -32,6 +33,14 @@ func main() {

fmt.Println("FeeEstimateQuery Example (HIP-1261)")

// On a fresh solo deployment the mirror node's FeeEstimationService races
// the importer ingesting the genesis fee schedule, so the first few calls
// return HTTP 400 "Unknown transaction type". Poll until it answers or 10
// minutes have elapsed.
if err := waitForFeeEstimationService(client); err != nil {
panic(fmt.Sprintf("%v : fee estimation service never became ready", err))
}

// Step 1: Create and freeze a transfer transaction. The query auto-freezes
// if the transaction is not already frozen, but freezing up front lets us
// reuse the same transaction across multiple estimates.
Expand Down Expand Up @@ -83,6 +92,26 @@ func main() {
fmt.Printf(" high_volume_multiplier: %d\n", helperEstimate.HighVolumeMultiplier)
}

func waitForFeeEstimationService(client *hiero.Client) error {
probe := hiero.NewTransferTransaction().
AddHbarTransfer(client.GetOperatorAccountID(), hiero.NewHbar(-1)).
AddHbarTransfer(client.GetOperatorAccountID(), hiero.NewHbar(1))

deadline := time.Now().Add(10 * time.Minute)
for time.Now().Before(deadline) {
_, err := hiero.NewFeeEstimateQuery().
SetMode(hiero.FeeEstimateModeIntrinsic).
SetTransaction(probe).
SetMaxAttempts(1).
Execute(client)
if err == nil {
return nil
}
time.Sleep(5 * time.Second)
}
return fmt.Errorf("timed out after 10 minutes")
}

func printEstimate(label string, response hiero.FeeEstimateResponse) {
fmt.Printf("\n%s estimate (tinycents):\n", label)
fmt.Printf(" network: %d (multiplier=%d)\n", response.NetworkFee.Subtotal, response.NetworkFee.Multiplier)
Expand Down
29 changes: 0 additions & 29 deletions sdk/fee_estimate_query_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
)

const (
mirrorSyncDelay = 2 * time.Second
feeEstimationProbeInterval = 5 * time.Second
feeEstimationProbeTimeout = 10 * time.Minute
)
Expand All @@ -32,10 +31,6 @@ var (
feeEstimationReadyErr error
)

func waitForMirrorNodeSync() {
time.Sleep(mirrorSyncDelay)
}

// waitForFeeEstimationServiceReady blocks until the mirror node's
// FeeEstimationService can answer a known-good probe query. Re-issues
// a fresh INTRINSIC estimate for a 1-hbar self-transfer every 5 seconds
Expand Down Expand Up @@ -110,8 +105,6 @@ func TestIntegrationFeeEstimateQueryTokenCreateTransaction(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeState).
Expand All @@ -137,8 +130,6 @@ func TestIntegrationFeeEstimateQueryTransferTransactionStateMode(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeState).
Expand All @@ -161,8 +152,6 @@ func TestIntegrationFeeEstimateQueryTransferTransactionIntrinsicMode(t *testing.
FreezeWith(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand All @@ -188,8 +177,6 @@ func TestIntegrationFeeEstimateQueryTransferTransactionDefaultModeIsIntrinsic(t
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

query := NewFeeEstimateQuery().SetTransaction(transaction)
require.Equal(t, FeeEstimateModeIntrinsic, query.GetMode())

Expand All @@ -212,8 +199,6 @@ func TestIntegrationFeeEstimateQueryTokenMintTransaction(t *testing.T) {
FreezeWith(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand All @@ -239,8 +224,6 @@ func TestIntegrationFeeEstimateQueryTopicCreateTransaction(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeState).
Expand All @@ -267,8 +250,6 @@ func TestIntegrationFeeEstimateQueryContractCreateTransaction(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeState).
Expand All @@ -294,8 +275,6 @@ func TestIntegrationFeeEstimateQueryFileCreateTransaction(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeState).
Expand All @@ -318,8 +297,6 @@ func TestIntegrationFeeEstimateQueryFileAppendTransactionAggregatesChunks(t *tes
FreezeWith(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand All @@ -342,8 +319,6 @@ func TestIntegrationFeeEstimateQueryTopicMessageSubmitSingleChunk(t *testing.T)
FreezeWith(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand All @@ -366,8 +341,6 @@ func TestIntegrationFeeEstimateQueryTopicMessageSubmitMultipleChunk(t *testing.T
FreezeWith(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand Down Expand Up @@ -405,8 +378,6 @@ func TestIntegrationFeeEstimateQueryWithHighVolumeThrottle(t *testing.T) {
_, err = transaction.SignWithOperator(env.Client)
require.NoError(t, err)

waitForMirrorNodeSync()

response, err := NewFeeEstimateQuery().
SetTransaction(transaction).
SetMode(FeeEstimateModeIntrinsic).
Expand Down
Loading