Skip to content

Commit

Permalink
Merge pull request #369 from /issues/321
Browse files Browse the repository at this point in the history
Comments in HowTo class, new StateEntity test with live CCTL data
  • Loading branch information
meywood authored Sep 26, 2024
2 parents 693da34 + 164cd5f commit 63f2796
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 19 deletions.
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 @@ -30,6 +28,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 @@ -63,6 +62,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 @@ -256,24 +256,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 @@ -399,6 +386,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 @@ -425,7 +413,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

0 comments on commit 63f2796

Please sign in to comment.