Skip to content

Commit 63f2796

Browse files
authored
Merge pull request #369 from /issues/321
Comments in HowTo class, new StateEntity test with live CCTL data
2 parents 693da34 + 164cd5f commit 63f2796

File tree

3 files changed

+338
-19
lines changed

3 files changed

+338
-19
lines changed

src/test/java/com/HowTo.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.casper.sdk.identifier.block.HashBlockIdentifier;
44
import com.casper.sdk.identifier.block.HeightBlockIdentifier;
5-
import com.casper.sdk.identifier.dictionary.StringDictionaryIdentifier;
65
import com.casper.sdk.identifier.entity.EntityAddrIdentifier;
76
import com.casper.sdk.identifier.era.IdEraIdentifier;
87
import com.casper.sdk.identifier.global.StateRootHashIdentifier;
@@ -17,7 +16,6 @@
1716
import com.casper.sdk.model.common.Ttl;
1817
import com.casper.sdk.model.deploy.Delegator;
1918
import com.casper.sdk.model.deploy.NamedArg;
20-
import com.casper.sdk.model.dictionary.DictionaryData;
2119
import com.casper.sdk.model.entity.AddressableEntity;
2220
import com.casper.sdk.model.entity.StateEntityResult;
2321
import com.casper.sdk.model.era.EraInfoData;
@@ -30,6 +28,7 @@
3028
import com.casper.sdk.model.transaction.*;
3129
import com.casper.sdk.model.transaction.entrypoint.CallEntryPoint;
3230
import com.casper.sdk.model.transaction.entrypoint.TransferEntryPoint;
31+
import com.casper.sdk.model.transaction.execution.ExecutionResultV2;
3332
import com.casper.sdk.model.transaction.pricing.FixedPricingMode;
3433
import com.casper.sdk.model.transaction.scheduling.Standard;
3534
import com.casper.sdk.model.transaction.target.Native;
@@ -63,6 +62,7 @@
6362
import static org.hamcrest.MatcherAssert.assertThat;
6463
import static org.hamcrest.core.Is.is;
6564
import static org.hamcrest.core.IsNull.notNullValue;
65+
import static org.hamcrest.core.IsNull.nullValue;
6666

6767
/**
6868
@@ -256,24 +256,11 @@ void getAccountInfo() {
256256
}
257257

258258
@Test
259-
/* TODO: Make it work */
259+
/* TODO */
260260
void getDictionaryItem() throws IOException {
261-
262-
final StatusData status = casperService.getStatus();
263-
final EraInfoData eraSummaryBlockHash = casperService.getEraSummary(new HashBlockIdentifier(status.getLastSwitchBlockHash().toString()));
264-
final PublicKey delegator = ((Delegator) eraSummaryBlockHash.getEraSummary().getStoredValue().getValue().getSeigniorageAllocations().get(0)).getDelegatorPublicKey();
265-
266-
String accountHash = delegator.generateAccountHash(true);
267-
268-
final StringDictionaryIdentifier key = StringDictionaryIdentifier.builder().dictionary(accountHash).build();
269-
270-
final DictionaryData stateDictionaryItem = casperService.getStateDictionaryItem(
271-
casperService.getStateRootHash().getStateRootHash(),
272-
key
273-
);
274-
275-
assert stateDictionaryItem.getDictionaryKey() != null;
276-
261+
// Now linked to issue #368
262+
// Need to first install a Contract with a built in Dictionary
263+
// Then query it with state_get_dictionary_item
277264
}
278265

279266

@@ -399,6 +386,7 @@ void putTransactionContractCep18() throws IOException, URISyntaxException, Value
399386
new NamedArg<>("decimals", new CLValueU8((byte) 11)),
400387
new NamedArg<>("name", new CLValueString("Acme Token")),
401388
new NamedArg<>("symbol", new CLValueString("ACME")),
389+
new NamedArg<>("total_supply", new CLValueU256(BigInteger.valueOf(500000))),
402390
new NamedArg<>("events_mode", new CLValueU8((byte) 0)),
403391
new NamedArg<>("id", new CLValueOption(Optional.of(new CLValueU64(BigInteger.valueOf(System.currentTimeMillis())))))
404392
);
@@ -425,7 +413,9 @@ void putTransactionContractCep18() throws IOException, URISyntaxException, Value
425413
assert result.getTransactionHash() != null;
426414

427415
final GetTransactionResult transactionResult = waitForTransaction(result.getTransactionHash());
416+
428417
assertThat(transactionResult, is(notNullValue()));
418+
assertThat(((ExecutionResultV2) transactionResult.getExecutionInfo().getExecutionResult()).getErrorMessage(), is(nullValue()));
429419

430420
}
431421

src/test/java/com/casper/sdk/model/entity/StateGetEntityTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,25 @@ void validateGetStateEntityLegacyAccount() throws IOException {
7272
final StateEntityResult entity = OBJECT_MAPPER.readValue(inputJson, StateEntityResult.class);
7373
assertInstanceOf(com.casper.sdk.model.account.Account.class, entity.getEntity());
7474
}
75+
76+
@Test
77+
void validateGetStateEntityActualSmartContractCctlReturnedResult() throws IOException {
78+
79+
final String inputJson = getPrettyJson(loadJsonFromFile("entity/getstateentity-smartcontract-actual-from-cctl.json"));
80+
81+
final StateEntityResult entity = OBJECT_MAPPER.readValue(inputJson, StateEntityResult.class);
82+
assertInstanceOf(AddressableEntity.class, entity.getEntity());
83+
assertInstanceOf(SmartContract.class, ((AddressableEntity) entity.getEntity()).getEntity().getEntityAddressKind());
84+
85+
final AddressableEntity contract = (AddressableEntity) entity.getEntity();
86+
87+
assertThat(contract.getNamedKeys().size(), is(11));
88+
assertThat(contract.getEntryPoints().size(), is(15));
89+
90+
assertThat(contract.getNamedKeys().get(0).getName(), is("allowances"));
91+
assertThat(contract.getNamedKeys().get(0).getKey(), is("uref-5e1239586b122bfe8ec9e3285f375d060ffbf90599fade7e807027fd228275cf-007"));
92+
93+
assertThat(contract.getEntryPoints().get(14).getV1().getName(), is("balance_of"));
94+
95+
}
7596
}

0 commit comments

Comments
 (0)