-
Notifications
You must be signed in to change notification settings - Fork 111
HIP-1313: High-volume entity creation #1633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
abb742e
feat: add high volume field in transaction
Dosik13 086cb21
test: add high volume unit tests
Dosik13 35740fe
test: add high volume e2e tests
Dosik13 1b18080
fix: resolve comments
Dosik13 6023c66
feat: add HighVolumePricingMultiplier field in TransactionRecord
Dosik13 b597a1c
test: add highVolumePricingMultiplier to the TransactionRecord unit t…
Dosik13 6a69e08
test: add transaction record check in the e2e tests
Dosik13 2cc7714
test: fix 1313 e2e test
Dosik13 833957f
feat: add example for 1313
Dosik13 77cb37f
refactor: make HighVolumePricingMultiplier nullable in TransactionRecord
Dosik13 d2f3435
chore: fix codacy in the example
Dosik13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,78 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| hiero "github.com/hiero-ledger/hiero-sdk-go/v2/sdk" | ||
| ) | ||
|
|
||
| func main() { | ||
| var client *hiero.Client | ||
| var err error | ||
|
|
||
| // Retrieving network type from environment variable HEDERA_NETWORK | ||
| client, err = hiero.ClientForName(os.Getenv("HEDERA_NETWORK")) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error creating client", err)) | ||
| } | ||
|
|
||
| // Retrieving operator ID from environment variable OPERATOR_ID | ||
| operatorAccountID, err := hiero.AccountIDFromString(os.Getenv("OPERATOR_ID")) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error converting string to AccountID", err)) | ||
| } | ||
|
|
||
| // Retrieving operator key from environment variable OPERATOR_KEY | ||
| operatorKey, err := hiero.PrivateKeyFromString(os.Getenv("OPERATOR_KEY")) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error converting string to PrivateKey", err)) | ||
| } | ||
|
|
||
| // Setting the client operator ID and key | ||
| client.SetOperator(operatorAccountID, operatorKey) | ||
|
|
||
| // Generate new key to use with new account | ||
| newKey, err := hiero.PrivateKeyGenerateEd25519() | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error generating PrivateKey", err)) | ||
| } | ||
|
|
||
| // HIP-1313: opt in to high-volume throttles by setting the high-volume flag. | ||
| // During busy periods, dynamic pricing applies and the transaction fee may be | ||
| // multiplied — SetMaxTransactionFee caps the price the operator is willing to pay. | ||
| transactionResponse, err := hiero.NewAccountCreateTransaction(). | ||
| SetKeyWithoutAlias(newKey.PublicKey()). | ||
| SetInitialBalance(hiero.NewHbar(1)). | ||
| SetHighVolume(true). | ||
| SetMaxTransactionFee(hiero.NewHbar(5)). | ||
| Execute(client) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error executing high-volume account create", err)) | ||
| } | ||
|
|
||
| receipt, err := transactionResponse.GetReceipt(client) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error getting receipt", err)) | ||
| } | ||
|
|
||
| fmt.Printf("account = %v\n", *receipt.AccountID) | ||
|
|
||
| // The high-volume pricing multiplier is reported on the transaction record. | ||
| // Value is divided by 1000 to get the actual multiplier (e.g. 1000 = 1.000x). | ||
| record, err := transactionResponse.GetRecord(client) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("%v : error getting record", err)) | ||
| } | ||
|
|
||
| fmt.Printf("transaction fee = %v\n", record.TransactionFee) | ||
| fmt.Printf("high-volume pricing multiplier = %s\n", formatMultiplier(record.HighVolumePricingMultiplier)) | ||
| } | ||
|
|
||
| // formatMultiplier renders the high-volume pricing multiplier from the record. | ||
| func formatMultiplier(m *uint64) string { | ||
| if m == nil { | ||
| return "(not set)" | ||
| } | ||
| return fmt.Sprintf("%.3fx", float64(*m)/1000) | ||
| } |
This file contains hidden or 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,88 @@ | ||
| //go:build all || e2e | ||
|
|
||
| package hiero | ||
|
|
||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIntegrationHIP1313HighVolumeAccountCreate(t *testing.T) { | ||
| t.Parallel() | ||
| env := NewIntegrationTestEnv(t) | ||
| defer CloseIntegrationTestEnv(env, nil) | ||
|
|
||
| newKey, err := PrivateKeyGenerateEd25519() | ||
| require.NoError(t, err) | ||
|
|
||
| resp, err := NewAccountCreateTransaction(). | ||
| SetKeyWithoutAlias(newKey). | ||
| SetNodeAccountIDs(env.NodeAccountIDs). | ||
| SetInitialBalance(NewHbar(1)). | ||
| SetHighVolume(true). | ||
| Execute(env.Client) | ||
| require.NoError(t, err) | ||
|
|
||
| receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) | ||
| require.NoError(t, err) | ||
|
|
||
| accountID := *receipt.AccountID | ||
| assert.NotEqual(t, AccountID{}, accountID) | ||
|
|
||
| record, err := resp.GetRecord(env.Client) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, record.HighVolumePricingMultiplier) | ||
| assert.GreaterOrEqual(t, *record.HighVolumePricingMultiplier, uint64(1000)) | ||
| } | ||
|
|
||
| func TestIntegrationHIP1313HighVolumeWithMaxTransactionFee(t *testing.T) { | ||
| t.Parallel() | ||
| env := NewIntegrationTestEnv(t) | ||
| defer CloseIntegrationTestEnv(env, nil) | ||
|
|
||
| newKey, err := PrivateKeyGenerateEd25519() | ||
| require.NoError(t, err) | ||
|
|
||
| resp, err := NewAccountCreateTransaction(). | ||
| SetKeyWithoutAlias(newKey). | ||
| SetNodeAccountIDs(env.NodeAccountIDs). | ||
| SetInitialBalance(NewHbar(1)). | ||
| SetHighVolume(true). | ||
| SetMaxTransactionFee(NewHbar(2)). | ||
| Execute(env.Client) | ||
| require.NoError(t, err) | ||
|
|
||
| receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) | ||
| require.NoError(t, err) | ||
|
|
||
| accountID := *receipt.AccountID | ||
| assert.NotEqual(t, AccountID{}, accountID) | ||
|
|
||
| // Verify fee charged does not exceed the max transaction fee | ||
| record, err := resp.GetRecord(env.Client) | ||
| require.NoError(t, err) | ||
| assert.True(t, record.TransactionFee.AsTinybar() <= NewHbar(2).AsTinybar()) | ||
| } | ||
|
|
||
| func TestIntegrationHIP1313HighVolumeInsufficientFee(t *testing.T) { | ||
| t.Parallel() | ||
| env := NewIntegrationTestEnv(t) | ||
| defer CloseIntegrationTestEnv(env, nil) | ||
|
|
||
| newKey, err := PrivateKeyGenerateEd25519() | ||
| require.NoError(t, err) | ||
|
|
||
| _, err = NewAccountCreateTransaction(). | ||
| SetKeyWithoutAlias(newKey). | ||
| SetNodeAccountIDs(env.NodeAccountIDs). | ||
| SetInitialBalance(NewHbar(1)). | ||
| SetHighVolume(true). | ||
| SetMaxTransactionFee(HbarFromTinybar(1)). | ||
| Execute(env.Client) | ||
|
|
||
| require.ErrorContains(t, err, "exceptional precheck status INSUFFICIENT_TX_FEE") | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.