github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/account_id_e2e_test.go (about) 1 //go:build all || e2e 2 // +build all e2e 3 4 package hedera 5 6 /*- 7 * 8 * Hedera Go SDK 9 * 10 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 */ 25 26 import ( 27 "encoding/hex" 28 "testing" 29 "time" 30 31 "github.com/stretchr/testify/require" 32 ) 33 34 func TestIntegrationAccountIDCanPopulateAccountNumber(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 privateKey, err := PrivateKeyGenerateEcdsa() 39 require.NoError(t, err) 40 publicKey := privateKey.PublicKey() 41 evmAddress := publicKey.ToEvmAddress() 42 evmAddressAccount, err := AccountIDFromEvmPublicAddress(evmAddress) 43 require.NoError(t, err) 44 tx, err := NewTransferTransaction().AddHbarTransfer(evmAddressAccount, NewHbar(1)). 45 AddHbarTransfer(env.OperatorID, NewHbar(-1)).Execute(env.Client) 46 require.NoError(t, err) 47 receipt, err := tx.SetIncludeChildren(true).SetValidateStatus(true).GetReceipt(env.Client) 48 require.NoError(t, err) 49 newAccountId := *receipt.Children[0].AccountID 50 idMirror, err := AccountIDFromEvmPublicAddress(evmAddress) 51 require.NoError(t, err) 52 time.Sleep(5 * time.Second) 53 error := idMirror.PopulateAccount(env.Client) 54 require.NoError(t, error) 55 require.Equal(t, newAccountId.Account, idMirror.Account) 56 } 57 58 func TestIntegrationAccountIDCanPopulateAccountAliasEvmAddress(t *testing.T) { 59 t.Parallel() 60 env := NewIntegrationTestEnv(t) 61 62 privateKey, err := PrivateKeyGenerateEcdsa() 63 require.NoError(t, err) 64 publicKey := privateKey.PublicKey() 65 evmAddress := publicKey.ToEvmAddress() 66 evmAddressAccount, err := AccountIDFromEvmPublicAddress(evmAddress) 67 require.NoError(t, err) 68 tx, err := NewTransferTransaction().AddHbarTransfer(evmAddressAccount, NewHbar(1)). 69 AddHbarTransfer(env.OperatorID, NewHbar(-1)).Execute(env.Client) 70 require.NoError(t, err) 71 receipt, err := tx.SetIncludeChildren(true).SetValidateStatus(true).GetReceipt(env.Client) 72 require.NoError(t, err) 73 newAccountId := *receipt.Children[0].AccountID 74 time.Sleep(5 * time.Second) 75 error := newAccountId.PopulateEvmAddress(env.Client) 76 require.NoError(t, error) 77 require.Equal(t, evmAddress, hex.EncodeToString(*newAccountId.AliasEvmAddress)) 78 } 79 80 func TestIntegrationAccountIDCanPopulateAccountAliasEvmAddressWithMirror(t *testing.T) { 81 t.Parallel() 82 env := NewIntegrationTestEnv(t) 83 84 privateKey, err := PrivateKeyGenerateEcdsa() 85 require.NoError(t, err) 86 publicKey := privateKey.PublicKey() 87 evmAddress := publicKey.ToEvmAddress() 88 evmAddressAccount, err := AccountIDFromEvmPublicAddress(evmAddress) 89 require.NoError(t, err) 90 tx, err := NewTransferTransaction().AddHbarTransfer(evmAddressAccount, NewHbar(1)). 91 AddHbarTransfer(env.OperatorID, NewHbar(-1)).Execute(env.Client) 92 require.NoError(t, err) 93 receipt, err := tx.SetIncludeChildren(true).SetValidateStatus(true).GetReceipt(env.Client) 94 require.NoError(t, err) 95 newAccountId := *receipt.Children[0].AccountID 96 time.Sleep(5 * time.Second) 97 error := newAccountId.PopulateEvmAddress(env.Client) 98 require.NoError(t, error) 99 require.Equal(t, evmAddress, hex.EncodeToString(*newAccountId.AliasEvmAddress)) 100 } 101 102 func TestIntegrationAccountIDCanPopulateAccountAliasEvmAddressWithNoMirror(t *testing.T) { 103 t.Parallel() 104 env := NewIntegrationTestEnv(t) 105 env.Client.mirrorNetwork = nil 106 privateKey, err := PrivateKeyGenerateEcdsa() 107 require.NoError(t, err) 108 publicKey := privateKey.PublicKey() 109 evmAddress := publicKey.ToEvmAddress() 110 evmAddressAccount, err := AccountIDFromEvmPublicAddress(evmAddress) 111 require.NoError(t, err) 112 tx, err := NewTransferTransaction().AddHbarTransfer(evmAddressAccount, NewHbar(1)). 113 AddHbarTransfer(env.OperatorID, NewHbar(-1)).Execute(env.Client) 114 require.NoError(t, err) 115 receipt, err := tx.SetIncludeChildren(true).SetValidateStatus(true).GetReceipt(env.Client) 116 require.NoError(t, err) 117 newAccountId := *receipt.Children[0].AccountID 118 env.Client.mirrorNetwork = nil 119 time.Sleep(5 * time.Second) 120 error := newAccountId.PopulateEvmAddress(env.Client) 121 require.Error(t, error) 122 } 123 124 func TestIntegrationAccountIDCanPopulateAccountAliasEvmAddressWithMirrorAndNoEvmAddress(t *testing.T) { 125 t.Parallel() 126 env := NewIntegrationTestEnv(t) 127 env.Client.mirrorNetwork = nil 128 privateKey, err := PrivateKeyGenerateEcdsa() 129 require.NoError(t, err) 130 publicKey := privateKey.PublicKey() 131 evmAddress := publicKey.ToEvmAddress() 132 evmAddressAccount, err := AccountIDFromEvmPublicAddress(evmAddress) 133 require.NoError(t, err) 134 tx, err := NewTransferTransaction().AddHbarTransfer(evmAddressAccount, NewHbar(1)). 135 AddHbarTransfer(env.OperatorID, NewHbar(-1)).Execute(env.Client) 136 require.NoError(t, err) 137 receipt, err := tx.SetIncludeChildren(true).SetValidateStatus(true).GetReceipt(env.Client) 138 require.NoError(t, err) 139 newAccountId := *receipt.Children[0].AccountID 140 env.Client.mirrorNetwork = nil 141 time.Sleep(5 * time.Second) 142 error := newAccountId.PopulateAccount(env.Client) 143 require.Error(t, error) 144 }