Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments in HowTo class, new StateEntity test with live CCTL data #369

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions src/test/java/com/HowTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.casper.sdk.identifier.block.HashBlockIdentifier;
import com.casper.sdk.identifier.block.HeightBlockIdentifier;
import com.casper.sdk.identifier.dictionary.StringDictionaryIdentifier;
import com.casper.sdk.identifier.entity.EntityAddrIdentifier;
import com.casper.sdk.identifier.era.IdEraIdentifier;
import com.casper.sdk.identifier.global.StateRootHashIdentifier;
Expand All @@ -17,7 +16,6 @@
import com.casper.sdk.model.common.Ttl;
import com.casper.sdk.model.deploy.Delegator;
import com.casper.sdk.model.deploy.NamedArg;
import com.casper.sdk.model.dictionary.DictionaryData;
import com.casper.sdk.model.entity.AddressableEntity;
import com.casper.sdk.model.entity.StateEntityResult;
import com.casper.sdk.model.era.EraInfoData;
Expand All @@ -29,6 +27,7 @@
import com.casper.sdk.model.transaction.*;
import com.casper.sdk.model.transaction.entrypoint.CallEntryPoint;
import com.casper.sdk.model.transaction.entrypoint.TransferEntryPoint;
import com.casper.sdk.model.transaction.execution.ExecutionResultV2;
import com.casper.sdk.model.transaction.pricing.FixedPricingMode;
import com.casper.sdk.model.transaction.scheduling.Standard;
import com.casper.sdk.model.transaction.target.Native;
Expand Down Expand Up @@ -62,6 +61,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;

/**
* @author [email protected]
Expand Down Expand Up @@ -255,24 +255,11 @@ void getAccountInfo() {
}

@Test
/* TODO: Make it work */
/* TODO */
void getDictionaryItem() throws IOException {

final StatusData status = casperService.getStatus();
final EraInfoData eraSummaryBlockHash = casperService.getEraSummary(new HashBlockIdentifier(status.getLastSwitchBlockHash().toString()));
final PublicKey delegator = ((Delegator) eraSummaryBlockHash.getEraSummary().getStoredValue().getValue().getSeigniorageAllocations().get(0)).getDelegatorPublicKey();

String accountHash = delegator.generateAccountHash(true);

final StringDictionaryIdentifier key = StringDictionaryIdentifier.builder().dictionary(accountHash).build();

final DictionaryData stateDictionaryItem = casperService.getStateDictionaryItem(
casperService.getStateRootHash().getStateRootHash(),
key
);

assert stateDictionaryItem.getDictionaryKey() != null;

// Now linked to issue #368
// Need to first install a Contract with a built in Dictionary
// Then query it with state_get_dictionary_item
}


Expand Down Expand Up @@ -398,6 +385,7 @@ void putTransactionContractCep18() throws IOException, URISyntaxException, Value
new NamedArg<>("decimals", new CLValueU8((byte) 11)),
new NamedArg<>("name", new CLValueString("Acme Token")),
new NamedArg<>("symbol", new CLValueString("ACME")),
new NamedArg<>("total_supply", new CLValueU256(BigInteger.valueOf(500000))),
new NamedArg<>("events_mode", new CLValueU8((byte) 0)),
new NamedArg<>("id", new CLValueOption(Optional.of(new CLValueU64(BigInteger.valueOf(System.currentTimeMillis())))))
);
Expand All @@ -424,7 +412,9 @@ void putTransactionContractCep18() throws IOException, URISyntaxException, Value
assert result.getTransactionHash() != null;

final GetTransactionResult transactionResult = waitForTransaction(result.getTransactionHash());

assertThat(transactionResult, is(notNullValue()));
assertThat(((ExecutionResultV2) transactionResult.getExecutionInfo().getExecutionResult()).getErrorMessage(), is(nullValue()));

}

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/casper/sdk/model/entity/StateGetEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,25 @@ void validateGetStateEntityLegacyAccount() throws IOException {
final StateEntityResult entity = OBJECT_MAPPER.readValue(inputJson, StateEntityResult.class);
assertInstanceOf(com.casper.sdk.model.account.Account.class, entity.getEntity());
}

@Test
void validateGetStateEntityActualSmartContractCctlReturnedResult() throws IOException {

final String inputJson = getPrettyJson(loadJsonFromFile("entity/getstateentity-smartcontract-actual-from-cctl.json"));

final StateEntityResult entity = OBJECT_MAPPER.readValue(inputJson, StateEntityResult.class);
assertInstanceOf(AddressableEntity.class, entity.getEntity());
assertInstanceOf(SmartContract.class, ((AddressableEntity) entity.getEntity()).getEntity().getEntityAddressKind());

final AddressableEntity contract = (AddressableEntity) entity.getEntity();

assertThat(contract.getNamedKeys().size(), is(11));
assertThat(contract.getEntryPoints().size(), is(15));

assertThat(contract.getNamedKeys().get(0).getName(), is("allowances"));
assertThat(contract.getNamedKeys().get(0).getKey(), is("uref-5e1239586b122bfe8ec9e3285f375d060ffbf90599fade7e807027fd228275cf-007"));

assertThat(contract.getEntryPoints().get(14).getV1().getName(), is("balance_of"));

}
}
Loading