github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_fee_schedule_update_transaction_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 "testing" 28 29 "github.com/stretchr/testify/assert" 30 31 "github.com/stretchr/testify/require" 32 ) 33 34 func TestIntegrationTokenFeeScheduleUpdateTransactionCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 tokenID, err := createFungibleToken(&env) 39 40 resp, err := NewTokenUpdateTransaction(). 41 SetTokenID(tokenID). 42 SetTokenSymbol("A"). 43 Execute(env.Client) 44 require.NoError(t, err) 45 46 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 47 require.NoError(t, err) 48 49 customFee := CustomFixedFee{ 50 CustomFee: CustomFee{ 51 FeeCollectorAccountID: &env.OperatorID, 52 }, 53 Amount: 1, 54 DenominationTokenID: &tokenID, 55 } 56 57 resp, err = NewTokenFeeScheduleUpdateTransaction(). 58 SetTokenID(tokenID). 59 SetCustomFees([]Fee{customFee}). 60 Execute(env.Client) 61 require.NoError(t, err) 62 63 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 64 require.NoError(t, err) 65 66 info, err := NewTokenInfoQuery(). 67 SetTokenID(tokenID). 68 SetNodeAccountIDs([]AccountID{resp.NodeID}). 69 Execute(env.Client) 70 require.NoError(t, err) 71 assert.True(t, len(info.CustomFees) > 0) 72 73 err = CloseIntegrationTestEnv(env, &tokenID) 74 require.NoError(t, err) 75 } 76 77 func TestIntegrationTokenFeeScheduleUpdateTransactionWithFractional(t *testing.T) { 78 t.Parallel() 79 env := NewIntegrationTestEnv(t) 80 81 tokenID, err := createFungibleToken(&env) 82 83 resp, err := NewTokenUpdateTransaction(). 84 SetTokenID(tokenID). 85 SetTokenSymbol("A"). 86 Execute(env.Client) 87 require.NoError(t, err) 88 89 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 90 require.NoError(t, err) 91 92 customFee := CustomFractionalFee{ 93 CustomFee: CustomFee{ 94 FeeCollectorAccountID: &env.OperatorID, 95 }, 96 Numerator: 1, 97 Denominator: 20, 98 MinimumAmount: 1, 99 MaximumAmount: 10, 100 AssessmentMethod: FeeAssessmentMethodExclusive, 101 } 102 103 resp, err = NewTokenFeeScheduleUpdateTransaction(). 104 SetTokenID(tokenID). 105 SetCustomFees([]Fee{customFee}). 106 Execute(env.Client) 107 require.NoError(t, err) 108 109 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 110 require.NoError(t, err) 111 112 info, err := NewTokenInfoQuery(). 113 SetTokenID(tokenID). 114 SetNodeAccountIDs([]AccountID{resp.NodeID}). 115 Execute(env.Client) 116 require.NoError(t, err) 117 assert.True(t, len(info.CustomFees) > 0) 118 119 err = CloseIntegrationTestEnv(env, &tokenID) 120 require.NoError(t, err) 121 } 122 123 func TestIntegrationTokenFeeScheduleUpdateTransactionNoFeeScheduleKey(t *testing.T) { 124 t.Parallel() 125 env := NewIntegrationTestEnv(t) 126 127 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 128 transaction.SetFeeScheduleKey(nil) 129 }) 130 131 resp, err := NewTokenUpdateTransaction(). 132 SetTokenID(tokenID). 133 SetTokenSymbol("A"). 134 Execute(env.Client) 135 require.NoError(t, err) 136 137 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 138 require.NoError(t, err) 139 140 customFee := CustomFixedFee{ 141 CustomFee: CustomFee{ 142 FeeCollectorAccountID: &env.OperatorID, 143 }, 144 Amount: 1, 145 DenominationTokenID: &tokenID, 146 } 147 148 resp, err = NewTokenFeeScheduleUpdateTransaction(). 149 SetTokenID(tokenID). 150 SetCustomFees([]Fee{customFee}). 151 Execute(env.Client) 152 require.NoError(t, err) 153 154 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 155 assert.Error(t, err) 156 if err != nil { 157 assert.Equal(t, "exceptional receipt status: TOKEN_HAS_NO_FEE_SCHEDULE_KEY", err.Error()) 158 } 159 160 err = CloseIntegrationTestEnv(env, &tokenID) 161 require.NoError(t, err) 162 } 163 164 func DisabledTestIntegrationTokenFeeScheduleUpdateTransactionWrongScheduleKey(t *testing.T) { // nolint 165 t.Parallel() 166 env := NewIntegrationTestEnv(t) 167 168 newKey, err := PrivateKeyGenerateEd25519() 169 require.NoError(t, err) 170 171 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 172 transaction. 173 SetFeeScheduleKey(newKey.PublicKey()) 174 }) 175 176 resp, err := NewTokenUpdateTransaction(). 177 SetTokenID(tokenID). 178 SetTokenSymbol("A"). 179 Execute(env.Client) 180 require.NoError(t, err) 181 182 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 183 require.NoError(t, err) 184 185 customFee := CustomFixedFee{ 186 CustomFee: CustomFee{ 187 FeeCollectorAccountID: &env.OperatorID, 188 }, 189 Amount: 1, 190 DenominationTokenID: &tokenID, 191 } 192 193 resp, err = NewTokenFeeScheduleUpdateTransaction(). 194 SetTokenID(tokenID). 195 SetCustomFees([]Fee{customFee}). 196 Execute(env.Client) 197 require.NoError(t, err) 198 199 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 200 assert.Error(t, err) 201 if err != nil { 202 assert.Equal(t, "exceptional receipt status: INVALID_CUSTOM_FEE_SCHEDULE_KEY", err.Error()) 203 } 204 205 info, err := NewTokenInfoQuery(). 206 SetTokenID(tokenID). 207 SetNodeAccountIDs([]AccountID{resp.NodeID}). 208 Execute(env.Client) 209 require.NoError(t, err) 210 assert.True(t, len(info.CustomFees) > 0) 211 212 err = CloseIntegrationTestEnv(env, &tokenID) 213 require.NoError(t, err) 214 } 215 216 func TestIntegrationTokenFeeScheduleUpdateTransactionScheduleAlreadyHasNoFees(t *testing.T) { 217 t.Parallel() 218 env := NewIntegrationTestEnv(t) 219 220 tokenID, err := createFungibleToken(&env) 221 222 resp, err := NewTokenUpdateTransaction(). 223 SetTokenID(tokenID). 224 SetTokenSymbol("A"). 225 Execute(env.Client) 226 require.NoError(t, err) 227 228 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 229 require.NoError(t, err) 230 231 resp, err = NewTokenFeeScheduleUpdateTransaction(). 232 SetTokenID(tokenID). 233 Execute(env.Client) 234 require.NoError(t, err) 235 236 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 237 require.ErrorContains(t, err, "exceptional receipt status: CUSTOM_SCHEDULE_ALREADY_HAS_NO_FEES") 238 239 err = CloseIntegrationTestEnv(env, &tokenID) 240 require.NoError(t, err) 241 } 242 243 func TestIntegrationTokenFeeScheduleUpdateTransactionFractionalFeeOnlyForFungibleCommon(t *testing.T) { 244 t.Parallel() 245 env := NewIntegrationTestEnv(t) 246 247 tokenID, err := createNft(&env) 248 249 resp, err := NewTokenUpdateTransaction(). 250 SetTokenID(tokenID). 251 SetTokenSymbol("A"). 252 Execute(env.Client) 253 require.NoError(t, err) 254 255 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 256 require.NoError(t, err) 257 258 customFee := CustomFractionalFee{ 259 CustomFee: CustomFee{ 260 FeeCollectorAccountID: &env.OperatorID, 261 }, 262 Numerator: 1, 263 Denominator: 20, 264 MinimumAmount: 1, 265 MaximumAmount: 10, 266 AssessmentMethod: FeeAssessmentMethodExclusive, 267 } 268 269 resp, err = NewTokenFeeScheduleUpdateTransaction(). 270 SetTokenID(tokenID). 271 SetCustomFees([]Fee{customFee}). 272 Execute(env.Client) 273 require.NoError(t, err) 274 275 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 276 assert.Error(t, err) 277 if err != nil { 278 assert.Equal(t, "exceptional receipt status: CUSTOM_FRACTIONAL_FEE_ONLY_ALLOWED_FOR_FUNGIBLE_COMMON", err.Error()) 279 } 280 281 err = CloseIntegrationTestEnv(env, &tokenID) 282 require.NoError(t, err) 283 } 284 285 func TestIntegrationTokenFeeScheduleUpdateTransactionDenominationMustBeFungibleCommon(t *testing.T) { 286 t.Parallel() 287 env := NewIntegrationTestEnv(t) 288 289 tokenID, err := createFungibleToken(&env) 290 require.NoError(t, err) 291 292 tokenIDNonFungible, err := createNft(&env) 293 require.NoError(t, err) 294 295 resp, err := NewTokenUpdateTransaction(). 296 SetTokenID(tokenID). 297 SetTokenSymbol("A"). 298 Execute(env.Client) 299 require.NoError(t, err) 300 301 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 302 require.NoError(t, err) 303 304 customFee := CustomFixedFee{ 305 CustomFee: CustomFee{ 306 FeeCollectorAccountID: &env.OperatorID, 307 }, 308 Amount: 5, 309 DenominationTokenID: &tokenIDNonFungible, 310 } 311 312 resp, err = NewTokenFeeScheduleUpdateTransaction(). 313 SetTokenID(tokenID). 314 SetCustomFees([]Fee{customFee}). 315 Execute(env.Client) 316 require.NoError(t, err) 317 318 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 319 assert.Error(t, err) 320 if err != nil { 321 assert.Equal(t, "exceptional receipt status: CUSTOM_FEE_DENOMINATION_MUST_BE_FUNGIBLE_COMMON", err.Error()) 322 } 323 } 324 325 func TestIntegrationTokenFeeScheduleUpdateTransactionCustomFeeListTooLong(t *testing.T) { 326 t.Parallel() 327 env := NewIntegrationTestEnv(t) 328 329 tokenID, err := createFungibleToken(&env) 330 require.NoError(t, err) 331 332 resp, err := NewTokenUpdateTransaction(). 333 SetTokenID(tokenID). 334 SetTokenSymbol("A"). 335 Execute(env.Client) 336 require.NoError(t, err) 337 338 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 339 require.NoError(t, err) 340 341 customFee := CustomFixedFee{ 342 CustomFee: CustomFee{ 343 FeeCollectorAccountID: &env.OperatorID, 344 }, 345 Amount: 1, 346 DenominationTokenID: &tokenID, 347 } 348 349 feeArr := make([]Fee, 0) 350 351 for i := 0; i < 21; i++ { 352 feeArr = append(feeArr, customFee) 353 } 354 355 resp, err = NewTokenFeeScheduleUpdateTransaction(). 356 SetTokenID(tokenID). 357 SetCustomFees(feeArr). 358 Execute(env.Client) 359 require.NoError(t, err) 360 361 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 362 assert.Error(t, err) 363 if err != nil { 364 assert.Equal(t, "exceptional receipt status: CUSTOM_FEES_LIST_TOO_LONG", err.Error()) 365 } 366 367 err = CloseIntegrationTestEnv(env, &tokenID) 368 require.NoError(t, err) 369 }