Skip to content
Closed
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
5 changes: 2 additions & 3 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ dependencies {

testAnnotationProcessor project(':pallet:pallet-codegen')

testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.testcontainers:testcontainers:1.17.1'
testImplementation 'org.testcontainers:junit-jupiter:1.17.1'
testImplementation 'org.testcontainers:testcontainers:1.17.2'
testImplementation 'org.testcontainers:junit-jupiter:1.17.2'
testImplementation 'org.awaitility:awaitility:4.2.0'
}
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ subprojects {
sourceCompatibility = '1.8'

dependencies {
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'com.google.guava:guava:31.1-jre'
implementation 'org.slf4j:slf4j-api:1.7.36'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.mockito:mockito-core:3.12.4'
testImplementation 'org.mockito:mockito-inline:3.12.4'
testImplementation 'org.slf4j:slf4j-simple:1.7.32'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation 'org.mockito:mockito-core:4.6.1'
testImplementation 'org.mockito:mockito-inline:4.6.1'
testImplementation 'org.slf4j:slf4j-simple:1.7.36'

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

test {
Expand Down
5 changes: 2 additions & 3 deletions pallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies {

testAnnotationProcessor project(':rpc:rpc-codegen')

testImplementation 'org.testcontainers:testcontainers:1.17.1'
testImplementation 'org.testcontainers:junit-jupiter:1.17.1'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.testcontainers:testcontainers:1.17.2'
testImplementation 'org.testcontainers:junit-jupiter:1.17.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
class Constants {
static final String STATE = "state";
static final String CLASS_NAME_TEMPLATE = "%sImpl";
static final String SCALE_READER_REGISTRY = "scaleReaderRegistry";
static final String SCALE_WRITER_REGISTRY = "scaleWriterRegistry";
static final String STORAGE_FACTORY_METHOD = "with";
static final String STORAGE_KEY_PROVIDER_FACTORY_METHOD = "of";
static final String STORAGE_KEY_PROVIDER_ADD_HASHERS = "use";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.strategyobject.substrateclient.scale.codegen.ScaleAnnotationParser;
import com.strategyobject.substrateclient.scale.codegen.reader.ReaderCompositor;
import com.strategyobject.substrateclient.scale.codegen.writer.WriterCompositor;
import com.strategyobject.substrateclient.scale.registries.ScaleReaderRegistry;
import com.strategyobject.substrateclient.scale.registries.ScaleWriterRegistry;
import lombok.NonNull;
import lombok.val;
import lombok.var;
Expand Down Expand Up @@ -104,15 +102,9 @@ private MethodSpec backFieldInitializer(String palletName,
.addAnnotation(suppressWarnings("unchecked", "rawtypes"))
.returns(TypeName.get(returnType));

declareReaderAndWriterRegistries(methodSpecBuilder);

val scaleAnnotationParser = new ScaleAnnotationParser(context);
val readerCompositor = ReaderCompositor.disallowOpenGeneric(
context,
SCALE_READER_REGISTRY);
val writerCompositor = WriterCompositor.disallowOpenGeneric(
context,
SCALE_WRITER_REGISTRY);
val readerCompositor = ReaderCompositor.disallowOpenGeneric(context);
val writerCompositor = WriterCompositor.disallowOpenGeneric(context);

assignStorageMapImpl(methodSpecBuilder,
palletName,
Expand Down Expand Up @@ -432,10 +424,4 @@ private void ensureNameIsSet(ExecutableElement method, AnnotationMirror storageA
method.getSimpleName());
}
}

private void declareReaderAndWriterRegistries(MethodSpec.Builder methodSpecBuilder) {
methodSpecBuilder
.addStatement("$1T $2L = $1T.getInstance()", ScaleReaderRegistry.class, SCALE_READER_REGISTRY)
.addStatement("$1T $2L = $1T.getInstance()", ScaleWriterRegistry.class, SCALE_WRITER_REGISTRY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static Stream<Arguments> getTestCasesForGetHash() {
@SuppressWarnings("unchecked")
private static <T> byte[] decode(Class<T> type, T value) {
val buf = new ByteArrayOutputStream();
((ScaleWriter<T>) ScaleWriterRegistry.getInstance().resolve(type)).write(value, buf);
((ScaleWriter<T>) ScaleWriterRegistry.resolve(type)).write(value, buf);

return buf.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static Stream<byte[]> getTestCasesForGetHash() {
@SuppressWarnings("unchecked")
private static <T> byte[] encode(Class<T> type, T value) {
val buf = new ByteArrayOutputStream();
((ScaleWriter<T>) ScaleWriterRegistry.getInstance().resolve(type)).write(value, buf);
((ScaleWriter<T>) ScaleWriterRegistry.resolve(type)).write(value, buf);

return buf.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ private static Stream<Arguments> getTestCasesForGetHash() {
return Stream.of(
Arguments.of(
10,
ScaleReaderRegistry.getInstance().resolve(Integer.class),
ScaleWriterRegistry.getInstance().resolve(Integer.class),
ScaleReaderRegistry.resolve(Integer.class),
ScaleWriterRegistry.resolve(Integer.class),
TwoX64Concat.getInstance(),
"0xa6b274250e6753f00a000000"
),
Expand All @@ -39,15 +39,15 @@ private static Stream<Arguments> getTestCasesForGetHash() {
SS58Codec.decode(
"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty")
.getAddress()),
ScaleReaderRegistry.getInstance().resolve(AccountId.class),
ScaleWriterRegistry.getInstance().resolve(AccountId.class),
ScaleReaderRegistry.resolve(AccountId.class),
ScaleWriterRegistry.resolve(AccountId.class),
Blake2B128Concat.getInstance(),
"0x4f9aea1afa791265fae359272badc1cf8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"
),
Arguments.of(
Hash256.fromBytes(HexConverter.toBytes("0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")),
ScaleReaderRegistry.getInstance().resolve(BlockHash.class),
ScaleWriterRegistry.getInstance().resolve(BlockHash.class),
ScaleReaderRegistry.resolve(BlockHash.class),
ScaleWriterRegistry.resolve(BlockHash.class),
Identity.getInstance(),
"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
)
Expand All @@ -60,8 +60,8 @@ private static Stream<Arguments> getTestCasesForExtractKey() {
new ByteArrayInputStream(
HexConverter.toBytes("0x5153cb1f00942ff401000000")
),
ScaleReaderRegistry.getInstance().resolve(Integer.class),
ScaleWriterRegistry.getInstance().resolve(Integer.class),
ScaleReaderRegistry.resolve(Integer.class),
ScaleWriterRegistry.resolve(Integer.class),
TwoX64Concat.getInstance(),
1,
0
Expand All @@ -70,8 +70,8 @@ private static Stream<Arguments> getTestCasesForExtractKey() {
new ByteArrayInputStream(
HexConverter.toBytes("0x969e061847da7e84337ea78dc577cd1d05000000")
),
ScaleReaderRegistry.getInstance().resolve(Integer.class),
ScaleWriterRegistry.getInstance().resolve(Integer.class),
ScaleReaderRegistry.resolve(Integer.class),
ScaleWriterRegistry.resolve(Integer.class),
Blake2B128Concat.getInstance(),
5,
0
Expand All @@ -90,8 +90,8 @@ private static Stream<Arguments> getTestCasesForExtractKey() {
new ByteArrayInputStream(
HexConverter.toBytes("0x")
),
ScaleReaderRegistry.getInstance().resolve(Void.class),
ScaleWriterRegistry.getInstance().resolve(Void.class),
ScaleReaderRegistry.resolve(Void.class),
ScaleWriterRegistry.resolve(Void.class),
Identity.getInstance(),
null,
0
Expand All @@ -101,8 +101,8 @@ private static Stream<Arguments> getTestCasesForExtractKey() {
HexConverter.toBytes("0x4f9aea1afa791265fae359272badc1cf8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" +
"a6b274250e6753f00a000000")
),
ScaleReaderRegistry.getInstance().resolve(AccountId.class),
ScaleWriterRegistry.getInstance().resolve(AccountId.class),
ScaleReaderRegistry.resolve(AccountId.class),
ScaleWriterRegistry.resolve(AccountId.class),
Blake2B128Concat.getInstance(),
AccountId.fromBytes(
SS58Codec.decode(
Expand All @@ -113,17 +113,17 @@ private static Stream<Arguments> getTestCasesForExtractKey() {
Arguments.of(
new ByteArrayInputStream(
HexConverter.toBytes("0xabcdef98765432100123456789abcdefabcdef98765432100123456789abcdef")),
ScaleReaderRegistry.getInstance().resolve(BlockHash.class),
ScaleWriterRegistry.getInstance().resolve(BlockHash.class),
ScaleReaderRegistry.resolve(BlockHash.class),
ScaleWriterRegistry.resolve(BlockHash.class),
Identity.getInstance(),
Hash256.fromBytes(HexConverter.toBytes("0xabcdef98765432100123456789abcdefabcdef98765432100123456789abcdef")),
0
),
Arguments.of(
new ByteArrayInputStream(
HexConverter.toBytes("0x518366b5b1bc7c99d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d")),
ScaleReaderRegistry.getInstance().resolve(BlockHash.class),
ScaleWriterRegistry.getInstance().resolve(BlockHash.class),
ScaleReaderRegistry.resolve(BlockHash.class),
ScaleWriterRegistry.resolve(BlockHash.class),
TwoX64Concat.getInstance(),
AccountId.fromBytes(
SS58Codec.decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ void societyVotes() throws Exception {
val state = RpcGeneratedSectionFactory.create(State.class, wsProvider);
val storage = StorageDoubleMapImpl.with(
state,
(ScaleReader<Void>) ScaleReaderRegistry.getInstance().resolve(Void.class),
(ScaleReader<Void>) ScaleReaderRegistry.resolve(Void.class),
StorageKeyProvider.of("Society", "Votes")
.use(KeyHasher.with((ScaleWriter<AccountId>) ScaleWriterRegistry.getInstance().resolve(AccountId.class),
(ScaleReader<AccountId>) ScaleReaderRegistry.getInstance().resolve(AccountId.class),
.use(KeyHasher.with((ScaleWriter<AccountId>) ScaleWriterRegistry.resolve(AccountId.class),
(ScaleReader<AccountId>) ScaleReaderRegistry.resolve(AccountId.class),
TwoX64Concat.getInstance()),
KeyHasher.with((ScaleWriter<AccountId>) ScaleWriterRegistry.getInstance().resolve(AccountId.class),
(ScaleReader<AccountId>) ScaleReaderRegistry.getInstance().resolve(AccountId.class),
KeyHasher.with((ScaleWriter<AccountId>) ScaleWriterRegistry.resolve(AccountId.class),
(ScaleReader<AccountId>) ScaleReaderRegistry.resolve(AccountId.class),
TwoX64Concat.getInstance())));
val alice = AccountId.fromBytes(
SS58Codec.decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private static Stream<Arguments> getTestCasesForGetBySingleKey() {
Arguments.of("System",
"BlockHash",
KeyHasher.with(
(ScaleWriter<Integer>) ScaleWriterRegistry.getInstance().resolve(Integer.class),
(ScaleReader<Integer>) ScaleReaderRegistry.getInstance().resolve(Integer.class),
(ScaleWriter<Integer>) ScaleWriterRegistry.resolve(Integer.class),
(ScaleReader<Integer>) ScaleReaderRegistry.resolve(Integer.class),
TwoX64Concat.getInstance()
),
2,
Expand All @@ -59,12 +59,12 @@ private static Stream<Arguments> getTestCasesForGetBySingleKey() {

@SuppressWarnings({"unchecked", "SameParameterValue"})
private static <T> ScaleReader<T> resolveReader(Class<T> clazz) {
return (ScaleReader<T>) ScaleReaderRegistry.getInstance().resolve(clazz);
return (ScaleReader<T>) ScaleReaderRegistry.resolve(clazz);
}

@SuppressWarnings({"unchecked", "SameParameterValue"})
private static <T> ScaleWriter<T> resolveWriter(Class<T> clazz) {
return (ScaleWriter<T>) ScaleWriterRegistry.getInstance().resolve(clazz);
return (ScaleWriter<T>) ScaleWriterRegistry.resolve(clazz);
}

private static Stream<Arguments> getTestCasesForGetByDoubleKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ void systemBlockHash() throws Exception {
val state = RpcGeneratedSectionFactory.create(State.class, wsProvider);
val storage = StorageMapImpl.with(
state,
(ScaleReader<BlockHash>) ScaleReaderRegistry.getInstance().resolve(BlockHash.class),
(ScaleReader<BlockHash>) ScaleReaderRegistry.resolve(BlockHash.class),
StorageKeyProvider.of("System", "BlockHash")
.use(KeyHasher.with((ScaleWriter<Integer>) ScaleWriterRegistry.getInstance().resolve(Integer.class),
(ScaleReader<Integer>) ScaleReaderRegistry.getInstance().resolve(Integer.class),
.use(KeyHasher.with((ScaleWriter<Integer>) ScaleWriterRegistry.resolve(Integer.class),
(ScaleReader<Integer>) ScaleReaderRegistry.resolve(Integer.class),
TwoX64Concat.getInstance())));

val actual = storage.get(0).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class StorageNMapImplTests {
private static StorageNMapImpl<BlockHash> newSystemBlockHashStorage(State state) {
return StorageNMapImpl.with(
state,
(ScaleReader<BlockHash>) ScaleReaderRegistry.getInstance().resolve(BlockHash.class),
(ScaleReader<BlockHash>) ScaleReaderRegistry.resolve(BlockHash.class),
StorageKeyProvider.of("System", "BlockHash")
.use(KeyHasher.with((ScaleWriter<BlockNumber>) ScaleWriterRegistry.getInstance().resolve(BlockNumber.class),
(ScaleReader<BlockNumber>) ScaleReaderRegistry.getInstance().resolve(BlockNumber.class),
.use(KeyHasher.with((ScaleWriter<BlockNumber>) ScaleWriterRegistry.resolve(BlockNumber.class),
(ScaleReader<BlockNumber>) ScaleReaderRegistry.resolve(BlockNumber.class),
TwoX64Concat.getInstance())));
}

Expand Down Expand Up @@ -97,7 +97,7 @@ void multiToDifferentStorages() throws Exception {
val state = RpcGeneratedSectionFactory.create(State.class, wsProvider);
val storageValue = StorageNMapImpl.with(
state,
ScaleReaderRegistry.getInstance().resolve(AccountId.class),
ScaleReaderRegistry.resolve(AccountId.class),
StorageKeyProvider.of("Sudo", "Key"));
val storageMap = newSystemBlockHashStorage(state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void sudoKey() throws Exception {
val state = RpcGeneratedSectionFactory.create(State.class, wsProvider);
val storage = StorageValueImpl.with(
state,
ScaleReaderRegistry.getInstance().resolve(AccountId.class),
ScaleReaderRegistry.resolve(AccountId.class),
StorageKeyProvider.of("Sudo", "Key"));

val actual = storage.get().get();
Expand All @@ -68,7 +68,7 @@ void sudoKeyAtGenesis() throws Exception {
val blockHash = chain.getBlockHash(BlockNumber.GENESIS).get();
val storage = StorageValueImpl.with(
state,
ScaleReaderRegistry.getInstance().resolve(AccountId.class),
ScaleReaderRegistry.resolve(AccountId.class),
StorageKeyProvider.of("Sudo", "Key"));

val actual = storage.at(blockHash).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Stream<Arguments> getTestCasesForGetHash() {
@SuppressWarnings("unchecked")
private static <T> byte[] decode(Class<T> type, T value) {
val buf = new ByteArrayOutputStream();
((ScaleWriter<T>) ScaleWriterRegistry.getInstance().resolve(type)).write(value, buf);
((ScaleWriter<T>) ScaleWriterRegistry.resolve(type)).write(value, buf);

return buf.toByteArray();
}
Expand Down
5 changes: 2 additions & 3 deletions rpc/rpc-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ dependencies {

testAnnotationProcessor project(':scale:scale-codegen')

testImplementation 'ch.qos.logback:logback-classic:1.2.11'
testImplementation 'org.testcontainers:testcontainers:1.17.1'
testImplementation 'org.testcontainers:junit-jupiter:1.17.1'
testImplementation 'org.testcontainers:testcontainers:1.17.2'
testImplementation 'org.testcontainers:junit-jupiter:1.17.2'
testImplementation 'org.awaitility:awaitility:4.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class AddressKindWriter implements ScaleWriter<AddressKind> {
public void write(@NonNull AddressKind value, @NonNull OutputStream stream, ScaleWriter<?>... writers) throws IOException {
Preconditions.checkArgument(writers == null || writers.length == 0);

((ScaleWriter<Byte>) ScaleWriterRegistry.getInstance().resolve(byte.class)).write(value.getValue(), stream);
((ScaleWriter<Byte>) ScaleWriterRegistry.resolve(byte.class)).write(value.getValue(), stream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BlockNumberU32Reader implements ScaleReader<BlockNumber> {
public BlockNumber read(@NonNull InputStream stream, ScaleReader<?>... readers) throws IOException {
Preconditions.checkArgument(readers == null || readers.length == 0);

val u32Reader = (ScaleReader<Long>) ScaleReaderRegistry.getInstance().resolve(ScaleType.U32.class);
val u32Reader = (ScaleReader<Long>) ScaleReaderRegistry.resolve(ScaleType.U32.class);
return BlockNumber.of(u32Reader.read(stream));
}
}
Loading