github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_update_transaction_hip540_e2e_test.go (about)

     1  //go:build all || e2e
     2  // +build all e2e
     3  
     4  package hedera
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  /*-
    14   *
    15   * Hedera Go SDK
    16   *
    17   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
    18   *
    19   * Licensed under the Apache License, Version 2.0 (the "License");
    20   * you may not use this file except in compliance with the License.
    21   * You may obtain a copy of the License at
    22   *
    23   *      http://www.apache.org/licenses/LICENSE-2.0
    24   *
    25   * Unless required by applicable law or agreed to in writing, software
    26   * distributed under the License is distributed on an "AS IS" BASIS,
    27   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    28   * See the License for the specific language governing permissions and
    29   * limitations under the License.
    30   *
    31   */
    32  
    33  // HIP-540 tests
    34  
    35  // KeyType represents different types of keys
    36  type KeyType int
    37  
    38  // Define enum values for different key types
    39  const (
    40  	WIPE_KEY KeyType = iota
    41  	KYC_KEY
    42  	SUPPLY_KEY
    43  	FREEZE_KEY
    44  	FEE_SCHEDULE_KEY
    45  	PAUSE_KEY
    46  	METADATA_KEY
    47  	ADMIN_KEY
    48  	ALL
    49  	LOWER_PRIVILEGE
    50  	NONE
    51  )
    52  
    53  func TestIntegrationTokenUpdateTransactionUpdateKeysToEmptyKeyListMakesTokenImmutable(t *testing.T) {
    54  	t.Parallel()
    55  	env := NewIntegrationTestEnv(t)
    56  
    57  	validNewKey, err := PrivateKeyGenerateEd25519()
    58  	require.NoError(t, err)
    59  
    60  	// Make token immutable
    61  	resp, tokenID, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, ALL, ALL, env.Client, NewKeyList(), env.OperatorKey, env.OperatorKey, NO_VALIDATION)
    62  	require.NoError(t, err)
    63  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    64  	require.NoError(t, err)
    65  
    66  	// Verify token is immutable
    67  	resp, err = updateTokenKeysHelper(t, tokenID, ALL, env.Client, validNewKey, env.OperatorKey, NO_VALIDATION)
    68  	require.NoError(t, err)
    69  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    70  	require.ErrorContains(t, err, "exceptional receipt status: TOKEN_IS_IMMUTABLE")
    71  
    72  	tokenInfo, err := NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
    73  	verifyAdminKeyNil(t, tokenInfo)
    74  	verifyLowerPrivilegeKeysNil(t, tokenInfo)
    75  }
    76  
    77  func TestIntegrationTokenUpdateTransactionUpdateKeysToZeroKeyFails(t *testing.T) {
    78  	t.Parallel()
    79  	env := NewIntegrationTestEnv(t)
    80  
    81  	zeroNewKey, err := ZeroKey()
    82  	require.NoError(t, err)
    83  
    84  	// Make token immutable
    85  	resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, ALL, ALL, env.Client, zeroNewKey, env.OperatorKey, env.OperatorKey, NO_VALIDATION)
    86  	require.NoError(t, err)
    87  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    88  
    89  	require.ErrorContains(t, err, "INVALID_SIGNATURE")
    90  }
    91  
    92  func TestIntegrationTokenUpdateTransactionUpdateLowerPrivilegeKeysWithAdminKeyFullValidation(t *testing.T) {
    93  	t.Parallel()
    94  	env := NewIntegrationTestEnv(t)
    95  
    96  	// Update lower privilege keys to zero key list with admin key
    97  	zeroKey, err := ZeroKey()
    98  	require.NoError(t, err)
    99  
   100  	resp, tokenID, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, ALL, LOWER_PRIVILEGE, env.Client, zeroKey, env.OperatorKey, env.OperatorKey, FULL_VALIDATION)
   101  	require.NoError(t, err)
   102  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   103  	require.NoError(t, err)
   104  	// Verify keys are set to zero
   105  	tokenInfo, err := NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   106  	verifyLowerPrivilegeKeys(t, tokenInfo, zeroKey)
   107  
   108  	// Update lower privilege keys to valid key list with admin key
   109  	validKey, err := PrivateKeyGenerateEd25519()
   110  	require.NoError(t, err)
   111  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, validKey, env.OperatorKey, FULL_VALIDATION)
   112  	require.NoError(t, err)
   113  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   114  	require.NoError(t, err)
   115  	// Verify keys are set to valid key
   116  	tokenInfo, err = NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   117  	verifyLowerPrivilegeKeys(t, tokenInfo, validKey.PublicKey())
   118  
   119  	// Update lower privilege keys to empty key list with admin key
   120  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, NewKeyList(), env.OperatorKey, FULL_VALIDATION)
   121  	require.NoError(t, err)
   122  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   123  	require.NoError(t, err)
   124  	// Verify keys are set to empty
   125  	tokenInfo, err = NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   126  	verifyLowerPrivilegeKeysNil(t, tokenInfo)
   127  }
   128  
   129  func TestIntegrationTokenUpdateTransactionUpdateLowerPrivilegeKeysWithAdminKeyNoValidation(t *testing.T) {
   130  	t.Parallel()
   131  	env := NewIntegrationTestEnv(t)
   132  
   133  	// Update lower privilege keys to zero key list with admin key
   134  	zeroKey, err := ZeroKey()
   135  	require.NoError(t, err)
   136  
   137  	resp, tokenID, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, ALL, LOWER_PRIVILEGE, env.Client, zeroKey, env.OperatorKey, env.OperatorKey, NO_VALIDATION)
   138  	require.NoError(t, err)
   139  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   140  	require.NoError(t, err)
   141  	// Verify keys are set to zero
   142  	tokenInfo, err := NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   143  	verifyLowerPrivilegeKeys(t, tokenInfo, zeroKey)
   144  
   145  	// Update lower privilege keys to valid key list with admin key
   146  	validKey, err := PrivateKeyGenerateEd25519()
   147  	require.NoError(t, err)
   148  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, validKey, env.OperatorKey, NO_VALIDATION)
   149  	require.NoError(t, err)
   150  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   151  	require.NoError(t, err)
   152  	// Verify keys are set to valid key
   153  	tokenInfo, err = NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   154  	verifyLowerPrivilegeKeys(t, tokenInfo, validKey.PublicKey())
   155  
   156  	// Update lower privilege keys to empty key list with admin key
   157  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, NewKeyList(), env.OperatorKey, NO_VALIDATION)
   158  	require.NoError(t, err)
   159  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   160  	require.NoError(t, err)
   161  	// Verify keys are set to empty
   162  	tokenInfo, err = NewTokenInfoQuery().SetTokenID(tokenID).Execute(env.Client)
   163  	verifyLowerPrivilegeKeysNil(t, tokenInfo)
   164  }
   165  
   166  func TestIntegrationTokenUpdateTransactionUpdateLowerPrivilegeKeysWithInvalidKeyFails(t *testing.T) {
   167  	t.Parallel()
   168  	env := NewIntegrationTestEnv(t)
   169  
   170  	adminKey, err := GeneratePrivateKey()
   171  	require.NoError(t, err)
   172  
   173  	nonAdminKey, err := GeneratePrivateKey()
   174  	require.NoError(t, err)
   175  
   176  	someKey, err := GeneratePrivateKey()
   177  	require.NoError(t, err)
   178  
   179  	// create the token
   180  	resp, tokenID, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, ALL, LOWER_PRIVILEGE, env.Client, nonAdminKey, adminKey, adminKey, NO_VALIDATION)
   181  	require.NoError(t, err)
   182  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   183  	require.NoError(t, err)
   184  
   185  	// Cannot remove tokens without admin key
   186  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, NewKeyList(), nonAdminKey, NO_VALIDATION)
   187  	require.NoError(t, err)
   188  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   189  	require.ErrorContains(t, err, "INVALID_SIGNATURE")
   190  
   191  	// Cannot upadate token with some random key
   192  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, NewKeyList(), someKey, NO_VALIDATION)
   193  	require.NoError(t, err)
   194  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   195  	require.ErrorContains(t, err, "INVALID_SIGNATURE")
   196  
   197  	zeroKey, err := ZeroKey()
   198  	require.NoError(t, err)
   199  
   200  	// Cannot upadate token with some random key
   201  	resp, err = updateTokenKeysHelper(t, tokenID, LOWER_PRIVILEGE, env.Client, zeroKey, someKey, NO_VALIDATION)
   202  	require.NoError(t, err)
   203  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   204  	require.ErrorContains(t, err, "INVALID_SIGNATURE")
   205  }
   206  
   207  func TestIntegrationTokenUpdateTransactionUpdateAdminKeyWithoutAlreadySetKeyFails(t *testing.T) {
   208  	t.Parallel()
   209  	env := NewIntegrationTestEnv(t)
   210  
   211  	someKey, err := GeneratePrivateKey()
   212  	require.NoError(t, err)
   213  
   214  	// Create token without keys and fail updating them
   215  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY, ADMIN_KEY} {
   216  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, NONE, keyType, env.Client, someKey, env.OperatorKey, env.OperatorKey, NO_VALIDATION)
   217  		require.NoError(t, err)
   218  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   219  		require.ErrorContains(t, err, "TOKEN_IS_IMMUTABLE")
   220  	}
   221  }
   222  
   223  func TestIntegrationTokenUpdateTransactionUpdateKeysLowerPrivKeysUpdateThemselvesNoValidation(t *testing.T) {
   224  	t.Parallel()
   225  	env := NewIntegrationTestEnv(t)
   226  
   227  	zeroNewKey, err := ZeroKey()
   228  	require.NoError(t, err)
   229  
   230  	validNewKey, err := PrivateKeyGenerateEd25519()
   231  	require.NoError(t, err)
   232  
   233  	initialKey := env.OperatorKey
   234  
   235  	// Update to valid key
   236  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY} {
   237  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, keyType, keyType, env.Client, validNewKey, initialKey, initialKey, NO_VALIDATION)
   238  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   239  		require.NoError(t, err)
   240  	}
   241  
   242  	// Zero keys
   243  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY} {
   244  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, keyType, keyType, env.Client, zeroNewKey, initialKey, initialKey, NO_VALIDATION)
   245  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   246  		require.NoError(t, err)
   247  	}
   248  }
   249  
   250  func TestIntegrationTokenUpdateTransactionUpdateKeysLowerPrivilegeKeysUpdateThemselvesFullValidation(t *testing.T) {
   251  	t.Parallel()
   252  	env := NewIntegrationTestEnv(t)
   253  
   254  	validNewKey, err := PrivateKeyGenerateEd25519()
   255  	require.NoError(t, err)
   256  
   257  	initialKey := env.OperatorKey
   258  
   259  	// Update to valid key
   260  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY} {
   261  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, keyType, keyType, env.Client, validNewKey, initialKey, initialKey, FULL_VALIDATION)
   262  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   263  		require.NoError(t, err)
   264  	}
   265  
   266  }
   267  
   268  func TestIntegrationTokenUpdateTransactionUpdateKeysLowerPrivilegeKeysUpdateFullValidationFails(t *testing.T) {
   269  	t.Parallel()
   270  	env := NewIntegrationTestEnv(t)
   271  
   272  	zeroNewKey, err := ZeroKey()
   273  	require.NoError(t, err)
   274  
   275  	initialKey := env.OperatorKey
   276  
   277  	// Zero out keys
   278  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY} {
   279  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, keyType, keyType, env.Client, zeroNewKey, initialKey, initialKey, FULL_VALIDATION)
   280  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   281  		require.ErrorContains(t, err, "exceptional receipt status: INVALID_SIGNATURE")
   282  	}
   283  }
   284  
   285  func TestIntegrationTokenUpdateTransactionRemoveKeysWithoutAdminKeyFails(t *testing.T) {
   286  	t.Parallel()
   287  	env := NewIntegrationTestEnv(t)
   288  
   289  	initialKey := env.OperatorKey
   290  
   291  	// Cannot remove keys without admin key
   292  	for _, keyType := range []KeyType{WIPE_KEY, KYC_KEY, SUPPLY_KEY, FREEZE_KEY, FEE_SCHEDULE_KEY, PAUSE_KEY, METADATA_KEY} {
   293  		resp, _, err := createTokenWithKeysAndUpdateTokenKeyHelper(t, keyType, keyType, env.Client, NewKeyList(), initialKey, initialKey, NO_VALIDATION)
   294  		_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   295  		require.ErrorContains(t, err, "TOKEN_IS_IMMUTABLE")
   296  	}
   297  }
   298  
   299  func TestIntegrationTokenUpdateTransactionRemoveKeysWithoutAdminKeySignFails(t *testing.T) {
   300  	t.Parallel()
   301  	env := NewIntegrationTestEnv(t)
   302  
   303  	newKey, err := PrivateKeyGenerateEd25519()
   304  	require.NoError(t, err)
   305  
   306  	initialKey, err := PrivateKeyGenerateEd25519()
   307  	require.NoError(t, err)
   308  
   309  	wipeKey, err := PrivateKeyGenerateEd25519()
   310  	require.NoError(t, err)
   311  
   312  	// Create NFT with wipe and supply keys
   313  	tokenID, err := createNft(&env, func(transaction *TokenCreateTransaction) {
   314  		transaction.
   315  			SetWipeKey(initialKey).
   316  			SetKycKey(initialKey).
   317  			SetSupplyKey(initialKey).
   318  			SetFreezeKey(initialKey).
   319  			SetFeeScheduleKey(initialKey).
   320  			SetPauseKey(initialKey).
   321  			SetMetadataKey(initialKey).
   322  			SetAdminKey(initialKey).
   323  			FreezeWith(env.Client)
   324  		transaction.Sign(initialKey)
   325  	})
   326  	require.NoError(t, err)
   327  
   328  	// Update supply key
   329  	tx1, err := NewTokenUpdateTransaction().
   330  		SetTokenID(tokenID).
   331  		SetWipeKey(newKey).
   332  		SetKycKey(newKey).
   333  		SetSupplyKey(newKey).
   334  		SetFreezeKey(newKey).
   335  		SetFeeScheduleKey(newKey).
   336  		SetPauseKey(newKey).
   337  		SetMetadataKey(newKey).
   338  		SetAdminKey(newKey).
   339  		SetKeyVerificationMode(NO_VALIDATION).
   340  		FreezeWith(env.Client)
   341  	assert.NoError(t, err)
   342  
   343  	// Cannot remove keys without admin key signing
   344  	resp, err := tx1.Sign(wipeKey).Execute(env.Client)
   345  	assert.NoError(t, err)
   346  
   347  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   348  	require.ErrorContains(t, err, "exceptional receipt status: INVALID_SIGNATURE")
   349  }
   350  
   351  func TestIntegrationTokenUpdateTransactionUpdateSupplyKeyFailsWhenSignWithWipeKey(t *testing.T) {
   352  	t.Parallel()
   353  	env := NewIntegrationTestEnv(t)
   354  
   355  	newSupplyKey, err := PrivateKeyGenerateEd25519()
   356  	require.NoError(t, err)
   357  
   358  	supplyKey, err := PrivateKeyGenerateEd25519()
   359  	require.NoError(t, err)
   360  
   361  	wipeKey, err := PrivateKeyGenerateEd25519()
   362  	require.NoError(t, err)
   363  
   364  	// Create NFT with wipe and supply keys
   365  	tokenID, err := createNft(&env, func(transaction *TokenCreateTransaction) {
   366  		transaction.
   367  			SetAdminKey(nil).
   368  			SetWipeKey(wipeKey).
   369  			SetSupplyKey(supplyKey)
   370  	})
   371  	require.NoError(t, err)
   372  
   373  	// Update supply key
   374  	tx, err := NewTokenUpdateTransaction().
   375  		SetTokenID(tokenID).
   376  		SetSupplyKey(newSupplyKey).
   377  		SetKeyVerificationMode(NO_VALIDATION).
   378  		FreezeWith(env.Client)
   379  	assert.NoError(t, err)
   380  
   381  	// Sign with the supply key
   382  	resp, err := tx.Sign(wipeKey).Execute(env.Client)
   383  	assert.NoError(t, err)
   384  
   385  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   386  	require.ErrorContains(t, err, "exceptional receipt status: INVALID_SIGNATURE")
   387  }
   388  
   389  func TestIntegrationTokenUpdateTransactionUpdateSupplyKeyToEmptyKeyAndVerifyItsImmutable(t *testing.T) {
   390  	t.Parallel()
   391  	env := NewIntegrationTestEnv(t)
   392  
   393  	newSupplyKey, err := PrivateKeyGenerateEd25519()
   394  	require.NoError(t, err)
   395  
   396  	supplyKey, err := PrivateKeyGenerateEd25519()
   397  	require.NoError(t, err)
   398  
   399  	// Create NFT with admin and supply keys
   400  	tokenID, err := createNft(&env, func(transaction *TokenCreateTransaction) {
   401  		transaction.SetSupplyKey(supplyKey).
   402  			SetAdminKey(env.OperatorKey)
   403  	})
   404  	require.NoError(t, err)
   405  
   406  	// Update supply key
   407  	tx, err := NewTokenUpdateTransaction().
   408  		SetTokenID(tokenID).
   409  		SetSupplyKey(NewKeyList()).
   410  		SetKeyVerificationMode(NO_VALIDATION).
   411  		FreezeWith(env.Client)
   412  	assert.NoError(t, err)
   413  
   414  	// Sign with the supply key
   415  	resp, err := tx.Sign(supplyKey).Execute(env.Client)
   416  	assert.NoError(t, err)
   417  
   418  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   419  	require.NoError(t, err)
   420  
   421  	tx, err = NewTokenUpdateTransaction().
   422  		SetTokenID(tokenID).
   423  		SetSupplyKey(newSupplyKey).
   424  		SetKeyVerificationMode(NO_VALIDATION).
   425  		FreezeWith(env.Client)
   426  	assert.NoError(t, err)
   427  
   428  	// Sign with the admin key
   429  	resp, err = tx.Sign(env.OperatorKey).Execute(env.Client)
   430  	assert.NoError(t, err)
   431  
   432  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   433  	require.ErrorContains(t, err, "exceptional receipt status: TOKEN_HAS_NO_SUPPLY_KEY")
   434  }
   435  
   436  func TestIntegrationTokenUpdateTransactionUpdateSupplyKeyFullValidationFails(t *testing.T) {
   437  	t.Parallel()
   438  	env := NewIntegrationTestEnv(t)
   439  
   440  	newSupplyKey, err := PrivateKeyGenerateEd25519()
   441  	require.NoError(t, err)
   442  
   443  	supplyKey, err := PrivateKeyGenerateEd25519()
   444  	require.NoError(t, err)
   445  
   446  	// Create NFT with supply key
   447  	tokenID, err := createNft(&env, func(transaction *TokenCreateTransaction) {
   448  		transaction.
   449  			SetSupplyKey(supplyKey).
   450  			SetAdminKey(nil)
   451  	})
   452  	require.NoError(t, err)
   453  
   454  	// Update supply key
   455  	tx, err := NewTokenUpdateTransaction().
   456  		SetTokenID(tokenID).
   457  		SetSupplyKey(newSupplyKey).
   458  		SetKeyVerificationMode(FULL_VALIDATION).
   459  		FreezeWith(env.Client)
   460  	assert.NoError(t, err)
   461  
   462  	_, err = supplyKey.SignTransaction(&tx.Transaction)
   463  	assert.NoError(t, err)
   464  
   465  	// Sign with the old supply key, should fail
   466  	resp, err := tx.Execute(env.Client)
   467  	assert.NoError(t, err)
   468  
   469  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   470  	require.ErrorContains(t, err, "exceptional receipt status: INVALID_SIGNATURE")
   471  
   472  	// Update supply key
   473  	tx2, err := NewTokenUpdateTransaction().
   474  		SetTokenID(tokenID).
   475  		SetSupplyKey(newSupplyKey).
   476  		SetKeyVerificationMode(FULL_VALIDATION).
   477  		FreezeWith(env.Client)
   478  	assert.NoError(t, err)
   479  
   480  	// Sign with only the new supply key, should fail
   481  	_, err = newSupplyKey.SignTransaction(&tx2.Transaction)
   482  	assert.NoError(t, err)
   483  
   484  	resp, err = tx2.Execute(env.Client)
   485  	assert.NoError(t, err)
   486  
   487  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   488  	require.ErrorContains(t, err, "exceptional receipt status: INVALID_SIGNATURE")
   489  }
   490  
   491  func TestIntegrationTokenUpdateTransactionUpdateSupplyKeyWithInvalidKey(t *testing.T) {
   492  	t.Parallel()
   493  	env := NewIntegrationTestEnv(t)
   494  	var invalidKey _Ed25519PublicKey
   495  	randomBytes := make([]byte, 32)
   496  	keyData := [32]byte{
   497  		0x01, 0x23, 0x45, 0x67,
   498  		0x89, 0xab, 0xcd, 0xef,
   499  		0xfe, 0xdc, 0xba, 0x98,
   500  		0x76, 0x54, 0x32, 0x10,
   501  		0x00, 0x11, 0x22, 0x33,
   502  		0x44, 0x55, 0x66, 0x77,
   503  		0x88, 0x99, 0xaa, 0xbb,
   504  		0xcc, 0xdd, 0xee, 0xff,
   505  	}
   506  	randomBytes = keyData[:]
   507  	copy(invalidKey.keyData[:], randomBytes)
   508  	invalidSupplyKey := PublicKey{
   509  		ed25519PublicKey: &invalidKey,
   510  	}
   511  
   512  	supplyKey, err := PrivateKeyGenerateEd25519()
   513  	require.NoError(t, err)
   514  
   515  	// Create NFT with supplyKey
   516  	tokenID, err := createNft(&env, func(transaction *TokenCreateTransaction) {
   517  		transaction.SetSupplyKey(supplyKey)
   518  	})
   519  	require.NoError(t, err)
   520  
   521  	// Update supply key
   522  	tx, err := NewTokenUpdateTransaction().
   523  		SetTokenID(tokenID).
   524  		SetSupplyKey(invalidSupplyKey).
   525  		SetKeyVerificationMode(NO_VALIDATION).
   526  		FreezeWith(env.Client)
   527  	assert.NoError(t, err)
   528  
   529  	_, err = supplyKey.SignTransaction(&tx.Transaction)
   530  	assert.NoError(t, err)
   531  
   532  	//Sign with the old supply key
   533  	_, err = tx.Execute(env.Client)
   534  	assert.ErrorContains(t, err, "exceptional precheck status INVALID_SUPPLY_KEY")
   535  
   536  }
   537  
   538  func createTokenWithKeysAndUpdateTokenKeyHelper(t *testing.T, createKeyType KeyType, updateKeyType KeyType, client *Client, newKey Key, initialKey Key, signerKey PrivateKey, verificationMode TokenKeyValidation) (TransactionResponse, TokenID, error) {
   539  	// Create Fungible token with keys
   540  	tx := NewTokenCreateTransaction().
   541  		SetTokenName("ffff").
   542  		SetTokenSymbol("F").
   543  		SetTreasuryAccountID(client.GetOperatorAccountID()).
   544  		SetFreezeDefault(false)
   545  
   546  	switch createKeyType {
   547  	case WIPE_KEY:
   548  		tx.SetWipeKey(initialKey)
   549  	case KYC_KEY:
   550  		tx.SetKycKey(initialKey)
   551  	case SUPPLY_KEY:
   552  		tx.SetSupplyKey(initialKey)
   553  	case FREEZE_KEY:
   554  		tx.SetFreezeKey(initialKey)
   555  	case FEE_SCHEDULE_KEY:
   556  		tx.SetFeeScheduleKey(initialKey)
   557  	case PAUSE_KEY:
   558  		tx.SetPauseKey(initialKey)
   559  	case METADATA_KEY:
   560  		tx.SetMetadataKey(initialKey)
   561  	case ADMIN_KEY:
   562  		tx.SetAdminKey(initialKey)
   563  	case LOWER_PRIVILEGE:
   564  		tx.SetWipeKey(initialKey).
   565  			SetKycKey(initialKey).
   566  			SetSupplyKey(initialKey).
   567  			SetFreezeKey(initialKey).
   568  			SetFeeScheduleKey(initialKey).
   569  			SetPauseKey(initialKey).
   570  			SetMetadataKey(initialKey)
   571  	case ALL:
   572  		tx.SetWipeKey(initialKey).
   573  			SetKycKey(initialKey).
   574  			SetSupplyKey(initialKey).
   575  			SetFreezeKey(initialKey).
   576  			SetFeeScheduleKey(initialKey).
   577  			SetPauseKey(initialKey).
   578  			SetMetadataKey(initialKey).
   579  			SetAdminKey(initialKey)
   580  	}
   581  	frozenTx, err := tx.FreezeWith(client)
   582  	require.NoError(t, err)
   583  	resp, err := frozenTx.Sign(signerKey).Execute(client)
   584  	require.NoError(t, err)
   585  	receipt, err := resp.SetValidateStatus(true).GetReceipt(client)
   586  	require.NoError(t, err)
   587  
   588  	resp, err = updateTokenKeysHelper(t, *receipt.TokenID, updateKeyType, client, newKey, signerKey, verificationMode)
   589  	return resp, *receipt.TokenID, err
   590  }
   591  
   592  func updateTokenKeysHelper(t *testing.T, tokenID TokenID, updateKeyType KeyType, client *Client, newKey Key, signerKey PrivateKey, verificationMode TokenKeyValidation) (TransactionResponse, error) {
   593  	privateKey, _ := newKey.(PrivateKey)
   594  	// Update the key
   595  	tx := NewTokenUpdateTransaction().
   596  		SetTokenID(tokenID).
   597  		SetKeyVerificationMode(verificationMode)
   598  
   599  	switch updateKeyType {
   600  	case WIPE_KEY:
   601  		tx.SetWipeKey(newKey)
   602  	case KYC_KEY:
   603  		tx.SetKycKey(newKey)
   604  	case SUPPLY_KEY:
   605  		tx.SetSupplyKey(newKey)
   606  	case FREEZE_KEY:
   607  		tx.SetFreezeKey(newKey)
   608  	case FEE_SCHEDULE_KEY:
   609  		tx.SetFeeScheduleKey(newKey)
   610  	case PAUSE_KEY:
   611  		tx.SetPauseKey(newKey)
   612  	case METADATA_KEY:
   613  		tx.SetMetadataKey(newKey)
   614  	case ADMIN_KEY:
   615  		tx.SetAdminKey(newKey)
   616  	case LOWER_PRIVILEGE:
   617  		tx.SetWipeKey(newKey).
   618  			SetKycKey(newKey).
   619  			SetSupplyKey(newKey).
   620  			SetFreezeKey(newKey).
   621  			SetFeeScheduleKey(newKey).
   622  			SetPauseKey(newKey).
   623  			SetMetadataKey(newKey)
   624  	case ALL:
   625  		tx.SetWipeKey(newKey).
   626  			SetKycKey(newKey).
   627  			SetSupplyKey(newKey).
   628  			SetFreezeKey(newKey).
   629  			SetFeeScheduleKey(newKey).
   630  			SetPauseKey(newKey).
   631  			SetMetadataKey(newKey).
   632  			SetAdminKey(newKey)
   633  	}
   634  	frozenTx, err := tx.FreezeWith(client)
   635  	assert.NoError(t, err)
   636  
   637  	if updateKeyType == ADMIN_KEY || updateKeyType == ALL || verificationMode == FULL_VALIDATION {
   638  		privateKey.SignTransaction(&tx.Transaction)
   639  		signerKey.SignTransaction(&tx.Transaction)
   640  		resp, err := frozenTx.Execute(client)
   641  		return resp, err
   642  
   643  	} else {
   644  		// Sign with the signer key
   645  		resp, err := frozenTx.Sign(signerKey).Execute(client)
   646  		return resp, err
   647  	}
   648  }
   649  
   650  func verifyAdminKey(t *testing.T, tokenInfo TokenInfo, expectedKey Key) {
   651  	assert.Equalf(t, expectedKey.String(), tokenInfo.AdminKey.String(), " admin key did not match")
   652  }
   653  
   654  func verifyAdminKeyNil(t *testing.T, tokenInfo TokenInfo) {
   655  	assert.Nil(t, tokenInfo.AdminKey)
   656  }
   657  
   658  func verifyLowerPrivilegeKeysNil(t *testing.T, tokenInfo TokenInfo) {
   659  	assert.Nil(t, tokenInfo.WipeKey)
   660  	assert.Nil(t, tokenInfo.KycKey)
   661  	assert.Nil(t, tokenInfo.SupplyKey)
   662  	assert.Nil(t, tokenInfo.FreezeKey)
   663  	assert.Nil(t, tokenInfo.FeeScheduleKey)
   664  	assert.Nil(t, tokenInfo.PauseKey)
   665  	assert.Nil(t, tokenInfo.MetadataKey)
   666  }
   667  
   668  func verifyLowerPrivilegeKeys(t *testing.T, tokenInfo TokenInfo, expectedKey Key) {
   669  	assert.Equalf(t, expectedKey.String(), tokenInfo.WipeKey.String(), "wipe key did not match")
   670  	assert.Equalf(t, expectedKey.String(), tokenInfo.KycKey.String(), "kyc key did not match")
   671  	assert.Equalf(t, expectedKey.String(), tokenInfo.SupplyKey.String(), "supply key did not match")
   672  	assert.Equalf(t, expectedKey.String(), tokenInfo.FreezeKey.String(), "freeze key did not match")
   673  	assert.Equalf(t, expectedKey.String(), tokenInfo.FeeScheduleKey.String(), "fee schedule key did not match")
   674  	assert.Equalf(t, expectedKey.String(), tokenInfo.PauseKey.String(), "pause key did not match")
   675  	assert.Equalf(t, expectedKey.String(), tokenInfo.MetadataKey.String(), "metadata key did not match")
   676  }