Skip to content

Commit

Permalink
Match TokenCreate mono behaviour (#9361)
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Tonev <[email protected]>
  • Loading branch information
petreze authored Oct 20, 2023
1 parent e454b2a commit 9b41eaa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
64 changes: 59 additions & 5 deletions hedera-node/hedera-app/src/xtest/java/contract/CreatesXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package contract;

import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ADMIN_KEY;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_RENEWAL_PERIOD;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TREASURY_ACCOUNT_FOR_TOKEN;
import static contract.CreatesXTestConstants.DECIMALS;
import static contract.CreatesXTestConstants.DECIMALS_BIG_INT;
import static contract.CreatesXTestConstants.DECIMALS_LONG;
Expand All @@ -24,6 +27,7 @@
import static contract.CreatesXTestConstants.FRACTIONAL_FEE;
import static contract.CreatesXTestConstants.INITIAL_TOTAL_SUPPLY;
import static contract.CreatesXTestConstants.INITIAL_TOTAL_SUPPLY_BIG_INT;
import static contract.CreatesXTestConstants.INVALID_EXPIRY;
import static contract.CreatesXTestConstants.MAX_SUPPLY;
import static contract.CreatesXTestConstants.MEMO;
import static contract.CreatesXTestConstants.NAME;
Expand All @@ -37,6 +41,7 @@
import static contract.CreatesXTestConstants.hederaTokenFactory;
import static contract.XTestConstants.AN_ED25519_KEY;
import static contract.XTestConstants.ERC20_TOKEN_ID;
import static contract.XTestConstants.INVALID_ACCOUNT_HEADLONG_ADDRESS;
import static contract.XTestConstants.OWNER_ADDRESS;
import static contract.XTestConstants.OWNER_HEADLONG_ADDRESS;
import static contract.XTestConstants.OWNER_ID;
Expand All @@ -49,7 +54,6 @@

import com.esaulpaugh.headlong.abi.Tuple;
import com.hedera.hapi.node.base.AccountID;
import com.hedera.hapi.node.base.ResponseCodeEnum;
import com.hedera.hapi.node.base.TokenID;
import com.hedera.hapi.node.base.TokenType;
import com.hedera.hapi.node.state.common.EntityIDPair;
Expand All @@ -75,6 +79,17 @@ public class CreatesXTest extends AbstractContractXTest {
new Tuple[] {TOKEN_KEY, TOKEN_KEY_TWO},
EXPIRY);

private static final Tuple INVALID_ACCOUNT_ID_HEDERA_TOKEN = hederaTokenFactory(
NAME,
SYMBOL,
INVALID_ACCOUNT_HEADLONG_ADDRESS,
MEMO,
true,
MAX_SUPPLY,
false,
new Tuple[] {TOKEN_KEY, TOKEN_KEY_TWO},
INVALID_EXPIRY);

@Override
protected void doScenarioOperations() {
// should successfully create fungible token v1
Expand Down Expand Up @@ -141,7 +156,7 @@ protected void doScenarioOperations() {
INITIAL_TOTAL_SUPPLY_BIG_INT,
DECIMALS_BIG_INT)
.array()),
ResponseCodeEnum.INVALID_ADMIN_KEY);
INVALID_ADMIN_KEY);

// should revert with autoRenewPeriod less than 2592000
runHtsCallAndExpectRevert(
Expand All @@ -161,7 +176,7 @@ protected void doScenarioOperations() {
INITIAL_TOTAL_SUPPLY_BIG_INT,
DECIMALS_BIG_INT)
.array()),
ResponseCodeEnum.INVALID_RENEWAL_PERIOD);
INVALID_RENEWAL_PERIOD);

// should successfully create fungible token with custom fees v1
runHtsCallAndExpectOnSuccess(
Expand Down Expand Up @@ -232,8 +247,6 @@ protected void doScenarioOperations() {
.array()),
assertSuccess());

// should revert when token has no supplyKey

// should successfully create non-fungible token with custom fees v1
runHtsCallAndExpectOnSuccess(
SENDER_BESU_ADDRESS,
Expand All @@ -257,6 +270,47 @@ protected void doScenarioOperations() {
.encodeCallWithArgs(DEFAULT_HEDERA_TOKEN, new Tuple[] {FIXED_FEE}, new Tuple[] {ROYALTY_FEE})
.array()),
assertSuccess());

// should revert with `INVALID_TREASURY_ACCOUNT_FOR_TOKEN` when passing invalid address for the treasury account
runHtsCallAndExpectRevert(
SENDER_BESU_ADDRESS,
Bytes.wrap(CreateTranslator.CREATE_FUNGIBLE_TOKEN_V1
.encodeCallWithArgs(
INVALID_ACCOUNT_ID_HEDERA_TOKEN, INITIAL_TOTAL_SUPPLY_BIG_INT, DECIMALS_BIG_INT)
.array()),
INVALID_TREASURY_ACCOUNT_FOR_TOKEN);

// should revert with `INVALID_TREASURY_ACCOUNT_FOR_TOKEN` when passing invalid address for the treasury account
runHtsCallAndExpectRevert(
SENDER_BESU_ADDRESS,
Bytes.wrap(CreateTranslator.CREATE_FUNGIBLE_WITH_CUSTOM_FEES_V1
.encodeCallWithArgs(
INVALID_ACCOUNT_ID_HEDERA_TOKEN,
INITIAL_TOTAL_SUPPLY_BIG_INT,
DECIMALS_BIG_INT,
// FixedFee
new Tuple[] {FIXED_FEE},
// FractionalFee
new Tuple[] {FRACTIONAL_FEE})
.array()),
INVALID_TREASURY_ACCOUNT_FOR_TOKEN);

// should revert with `INVALID_TREASURY_ACCOUNT_FOR_TOKEN` when passing invalid address for the treasury account
runHtsCallAndExpectRevert(
SENDER_BESU_ADDRESS,
Bytes.wrap(CreateTranslator.CREATE_NON_FUNGIBLE_TOKEN_V1
.encodeCallWithArgs(INVALID_ACCOUNT_ID_HEDERA_TOKEN)
.array()),
INVALID_TREASURY_ACCOUNT_FOR_TOKEN);

// should revert with `INVALID_TREASURY_ACCOUNT_FOR_TOKEN` when passing invalid address for the treasury account
runHtsCallAndExpectRevert(
SENDER_BESU_ADDRESS,
Bytes.wrap(CreateTranslator.CREATE_NON_FUNGIBLE_TOKEN_WITH_CUSTOM_FEES_V1
.encodeCallWithArgs(
INVALID_ACCOUNT_ID_HEDERA_TOKEN, new Tuple[] {FIXED_FEE}, new Tuple[] {ROYALTY_FEE})
.array()),
INVALID_TREASURY_ACCOUNT_FOR_TOKEN);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class CreatesXTestConstants {
Tuple.of(false, INVALID_ACCOUNT_HEADLONG_ADDRESS, new byte[] {}, new byte[] {}, asAddress("")));

static final Tuple EXPIRY = Tuple.of(SECOND, OWNER_HEADLONG_ADDRESS, AUTO_RENEW_PERIOD);
static final Tuple INVALID_EXPIRY = Tuple.of(SECOND, INVALID_ACCOUNT_HEADLONG_ADDRESS, AUTO_RENEW_PERIOD);

static final Tuple FIXED_FEE = Tuple.of(100L, ERC20_TOKEN_ADDRESS, false, false, OWNER_HEADLONG_ADDRESS);
static final Tuple FRACTIONAL_FEE = Tuple.of(100L, 100L, 100L, 100L, true, OWNER_HEADLONG_ADDRESS);
Expand Down

0 comments on commit 9b41eaa

Please sign in to comment.