-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added token_mint_transaction_test
- Loading branch information
1 parent
a9cec57
commit e1da8df
Showing
1 changed file
with
116 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,116 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTokenMintTransaction_Execute(t *testing.T) { | ||
var client *Client | ||
|
||
network := os.Getenv("HEDERA_NETWORK") | ||
|
||
if network == "previewnet" { | ||
client = ClientForPreviewnet() | ||
} | ||
|
||
var err error | ||
client, err = ClientFromJsonFile(os.Getenv("CONFIG_FILE")) | ||
|
||
if err != nil { | ||
client = ClientForTestnet() | ||
} | ||
|
||
client.SetMirrorNetwork([]string{"hcs.previewnet.mirrornode.hedera.com:5600"}) | ||
|
||
configOperatorID := os.Getenv("OPERATOR_ID") | ||
configOperatorKey := os.Getenv("OPERATOR_KEY") | ||
var operatorKey PrivateKey | ||
var operatorAccountID AccountID | ||
|
||
if configOperatorID != "" && configOperatorKey != "" { | ||
operatorAccountID, err = AccountIDFromString(configOperatorID) | ||
assert.NoError(t, err) | ||
|
||
operatorKey, err = PrivateKeyFromString(configOperatorKey) | ||
assert.NoError(t, err) | ||
|
||
client.SetOperator(operatorAccountID, operatorKey) | ||
} | ||
|
||
newKey, err := GeneratePrivateKey() | ||
assert.NoError(t, err) | ||
|
||
newBalance := NewHbar(1) | ||
|
||
assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) | ||
|
||
resp, err := NewAccountCreateTransaction(). | ||
SetKey(newKey.PublicKey()). | ||
SetMaxTransactionFee(NewHbar(2)). | ||
SetInitialBalance(newBalance). | ||
Execute(client) | ||
assert.NoError(t, err) | ||
|
||
receipt, err := resp.GetReceipt(client) | ||
assert.NoError(t, err) | ||
|
||
accountID := *receipt.AccountID | ||
|
||
resp, err = NewTokenCreateTransaction(). | ||
SetName("ffff"). | ||
SetSymbol("F"). | ||
SetDecimals(3). | ||
SetInitialSupply(1000000). | ||
SetTreasury(operatorAccountID). | ||
SetAdminKey(operatorKey.PublicKey()). | ||
SetFreezeKey(operatorKey.PublicKey()). | ||
SetWipeKey(operatorKey.PublicKey()). | ||
SetKycKey(operatorKey.PublicKey()). | ||
SetSupplyKey(operatorKey.PublicKey()). | ||
SetFreezeDefault(false). | ||
SetExpirationTime(uint64(time.Now().Unix() + 86400*90)). | ||
Execute(client) | ||
assert.NoError(t, err) | ||
|
||
receipt, err = resp.GetReceipt(client) | ||
assert.NoError(t, err) | ||
|
||
tokenID := *receipt.TokenID | ||
|
||
resp, err = NewTokenMintTransaction(). | ||
SetNodeAccountIDs([]AccountID{resp.NodeID}). | ||
SetAmount(10). | ||
SetTokenID(tokenID). | ||
Execute(client) | ||
assert.NoError(t, err) | ||
|
||
_, err = resp.GetReceipt(client) | ||
assert.NoError(t, err) | ||
|
||
resp, err = NewTokenDeleteTransaction(). | ||
SetNodeAccountIDs([]AccountID{resp.NodeID}). | ||
SetTokenID(tokenID). | ||
Execute(client) | ||
assert.NoError(t, err) | ||
|
||
_, err = resp.GetReceipt(client) | ||
assert.NoError(t, err) | ||
|
||
tx, err := NewAccountDeleteTransaction(). | ||
SetAccountID(accountID). | ||
SetTransferAccountID(client.GetOperatorID()). | ||
FreezeWith(client) | ||
assert.NoError(t, err) | ||
|
||
resp, err = tx. | ||
Sign(operatorKey). | ||
Sign(newKey). | ||
Execute(client) | ||
assert.NoError(t, err) | ||
|
||
_, err = resp.GetReceipt(client) | ||
assert.NoError(t, err) | ||
} |