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

Support RPC 0.4.0 #281

Merged
merged 99 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
525b710
Bump starknet-devnet to 0.5.5
Jul 14, 2023
a362f21
Update Messages to match openrpc 0.4.0-rc spec
Jul 17, 2023
86178d1
Add getEstimateMessageFee (untested)
Jul 17, 2023
fa13547
Merge branch 'main' into feat/estimate_message_fee-rpc-0.4.0
DelevoXDG Jul 18, 2023
a86c07e
Update naming (MessageL2ToL1) in SimulatedTransaction
Jul 18, 2023
c3705a8
Merge branch 'main'
DelevoXDG Jul 21, 2023
11e7ce5
Split DeclareTransaction to match oneOf (rpc 0.4.0-rc2)
DelevoXDG Jul 25, 2023
5f8936f
Add execution_status, finality_status, revert_reason
DelevoXDG Jul 25, 2023
6303c4b
Add TransactionHashPair to support new block body (rpc 0.4.0-rc2)
DelevoXDG Jul 25, 2023
1282a94
Update transactions (rpc 0.4.0-rc2)
DelevoXDG Jul 25, 2023
274a4b1
Update deserializers
DelevoXDG Jul 25, 2023
d443aea
Txn hash also removed from L1_Handler in RPC
DelevoXDG Jul 25, 2023
47a7367
Remove "to_address" from GatewayMessageL1ToL2
DelevoXDG Jul 26, 2023
f45981b
Set correct version in DeclareTransactionV2
DelevoXDG Jul 26, 2023
43ef424
Add entry_point_selector to RpcMessageL1ToL2
DelevoXDG Jul 26, 2023
c4de245
Add extra options to execution and finality status (starknet 0.12.1)
DelevoXDG Jul 26, 2023
0a9b524
Set non-required (in rpc 0.4) dataclass fields to null
DelevoXDG Jul 27, 2023
a4a47f8
Restore the old order of fields in Transactions
DelevoXDG Jul 27, 2023
a4db374
Finish restoring order
DelevoXDG Jul 27, 2023
b6141f6
Fix order 3
DelevoXDG Jul 27, 2023
84f05d6
Update finality_status
DelevoXDG Jul 28, 2023
175d9b3
Merge branch 'main' into feat/support-rpc-0.4.0
DelevoXDG Aug 2, 2023
4fee8e0
Correct typo
DelevoXDG Aug 4, 2023
61c1d20
Add deserializers to json for all TransactionPayloads
DelevoXDG Aug 4, 2023
f94bc8a
Add new JsonRpcTransactionPayloadSerializer
DelevoXDG Aug 4, 2023
50865d7
Add EstimateTransactionFeePayloadSerializer; Use new serializers for …
DelevoXDG Aug 4, 2023
28612e3
Remove old JsonRpcTransactionPayloadPolymorphicSerializer
DelevoXDG Aug 4, 2023
09963e0
Update TransactionPayload for consitency with Transaction dataclass
DelevoXDG Aug 4, 2023
60e702a
Apply format
DelevoXDG Aug 4, 2023
44af2d6
Remove unnecessary constructor arg
DelevoXDG Aug 4, 2023
c665506
Fix format
DelevoXDG Aug 4, 2023
05498f0
Add @SerialName's to Message dataclasses
DelevoXDG Aug 4, 2023
3011979
Remove TransactionHashPair
DelevoXDG Aug 4, 2023
0d2b98e
Update revertReason to be nullable
DelevoXDG Aug 4, 2023
d37e363
Add REVERTED TransactionStatus
DelevoXDG Aug 4, 2023
0d3b77b
Improve exception reasons in serializers
DelevoXDG Aug 7, 2023
464d385
Format
DelevoXDG Aug 7, 2023
dd4f768
Add mockUpdatedReceiptRpcProvider
DelevoXDG Aug 8, 2023
ade6e08
Review changes
DelevoXDG Aug 8, 2023
0b57c4f
Bump devnet to 0.6.0a0; Mock getTransactionReceipt in rpc tests
DelevoXDG Aug 8, 2023
6f14434
revert_reason -> revert_error (gateway)
DelevoXDG Aug 8, 2023
c57337b
Update isAccepted
DelevoXDG Aug 8, 2023
f0cd374
Update mocked rpc receipt
DelevoXDG Aug 8, 2023
775ee4d
Format
DelevoXDG Aug 8, 2023
67d78f2
Update maxFee to prevent test from failing
DelevoXDG Aug 8, 2023
897473d
Log http requests and responses to debug CI
DelevoXDG Aug 8, 2023
09fc297
Update contractDefintion in DeclareTransaction dataclasses
DelevoXDG Aug 8, 2023
d7f8fd0
Recalculate class hash to fix; Specify declare version in test names
DelevoXDG Aug 8, 2023
ef563cb
Fix incorrect output dirs in compileContracts task
DelevoXDG Aug 8, 2023
21ba146
Merge branch 'fix/291-out-dirs-compile-contracts-task' into feat/supp…
DelevoXDG Aug 8, 2023
c181f18
Change classHash (again)
DelevoXDG Aug 8, 2023
8ed66eb
Add temporary normal case statuses
DelevoXDG Aug 8, 2023
827031f
Add basic integration getters test
DelevoXDG Aug 9, 2023
ee5d879
Refactor integration tests config
DelevoXDG Aug 9, 2023
f5c41f7
Move `events` to base TransactionReceipt class
DelevoXDG Aug 9, 2023
a886433
Merge 'fix/288-estimate-declare-fee'
DelevoXDG Aug 9, 2023
1744e11
Set up env on CI
DelevoXDG Aug 9, 2023
c7e3235
Format
DelevoXDG Aug 9, 2023
6f14bef
Add fetching env secrets to Checks action
DelevoXDG Aug 10, 2023
9b42924
Disable estimate declaree fee test for gateway
DelevoXDG Aug 10, 2023
09d2009
Merge branch 'main' into feat/support-rpc-0.4.0
DelevoXDG Aug 10, 2023
dd4139e
Update estimate_message_fee mock test; misc changes
DelevoXDG Aug 10, 2023
5d30f88
Update path to integration tests config file
DelevoXDG Aug 11, 2023
409b6b1
Update Rpc Transaction Receipt Deserializer; Address some issues
DelevoXDG Aug 11, 2023
86c8896
Add old json names for finality status
DelevoXDG Aug 11, 2023
a0d476d
Add isPending field for Processed Transaction Receipt
DelevoXDG Aug 11, 2023
0c08a06
Add some more getters tests
DelevoXDG Aug 11, 2023
9a54007
Format
DelevoXDG Aug 11, 2023
8918aa3
Update JsonRpcGetBlockWithTransactionsPolymorphicSerializer; Add getB…
DelevoXDG Aug 11, 2023
dad0789
Integration tests: Change skipping; Add AccountTest
DelevoXDG Aug 16, 2023
3941124
Check enabled - all tests cases; Add .env template
DelevoXDG Aug 16, 2023
b281b23
Add vars that have default values to templated
DelevoXDG Aug 16, 2023
e0ced84
Add TODO for #294
DelevoXDG Aug 16, 2023
324db0e
Merge Messsage dataclasses; Add integration tests for messages; Updat…
DelevoXDG Aug 16, 2023
fcfcb5d
Bump devnet to 0.6.0; Set different salt in tests for Gateway and RPC…
DelevoXDG Aug 16, 2023
59afff4
Remove PascalCase
DelevoXDG Aug 16, 2023
b4a6cb1
Accept both revert_reason and revert_error
DelevoXDG Aug 16, 2023
73f8242
Recalculate classHashes (cairo 0) - 0.12.1
DelevoXDG Aug 16, 2023
36ed534
Rename GettersTest to ProviderTest
DelevoXDG Aug 16, 2023
7f67222
Reenable non-gas integration tests on CI
DelevoXDG Aug 16, 2023
0bb3544
Remove beforeEach from integration.account test
DelevoXDG Aug 16, 2023
f807a9a
Disable int tests by default; Add int instructions to README; Rename …
DelevoXDG Aug 17, 2023
77cc9a6
Rename ConfigUtils to IntegrationConfig; Speed up IntegrationConfig i…
DelevoXDG Aug 17, 2023
6a9e6c9
Format
DelevoXDG Aug 17, 2023
8e34445
Update hooks in readme
DelevoXDG Aug 17, 2023
dd8f123
Add DeclareTransactionV0 and test
DelevoXDG Aug 17, 2023
01c825e
Update .gitignore
DelevoXDG Aug 17, 2023
d1f7a25
Format
DelevoXDG Aug 17, 2023
b0bc4ea
Format; Clarify README
DelevoXDG Aug 17, 2023
d8bd4b0
Remove irrelevant TODO
DelevoXDG Aug 17, 2023
b871031
Add extra integration tests
DelevoXDG Aug 17, 2023
d342bc9
Disable integration tests on CI
DelevoXDG Aug 17, 2023
66e81dd
Replace integration test variables with INTEGRATION_TEST_MODE
DelevoXDG Aug 18, 2023
dd23fef
Add call contract integration test
DelevoXDG Aug 18, 2023
c607874
Add mock test for pending transaction receipt
DelevoXDG Aug 18, 2023
1d6f89e
Drop STARKNET_JVM prefix from CI secrets
DelevoXDG Aug 18, 2023
acbcbe0
Misc changes
DelevoXDG Aug 18, 2023
3c482d6
Remove loading env vars on CI
DelevoXDG Aug 18, 2023
075aa01
Make empty config when integrationTestMode=disabled
DelevoXDG Aug 18, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ venv
# Exclude account temp files
lib/src/test/resources/*account
lib/src/test/resources/compiled*
integration_tests.env

# Exclude native builds outputs
crypto/pedersen/crypto-cpp
Expand Down
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,45 @@ var account2 = new StandardAccount(provider2, accountAddress2, privateKey2);
### Hooks
Run
```
./gradlew addKtlintFormatGitPreCommitHook
./gradlew addKtlintCheckGitPreCommitHook
./gradlew installKotlinterPrePushHook
```

## Running tests

Running tests requires to have both cairo-lang and starknet-devnet installed.
These are distributed as python packages. Run
### Prerequisites
Running tests requires to have both `cairo-lang` and `starknet-devnet` installed.
These are distributed as python packages. To install required dependencies, run:

```shell
pip install -r requirements.txt
```
### Regular Tests
Use the following command to run tests:
```shell
./gradlew :lib:test
```

to install required dependencies.
### Integration Tests
Running tests for integration network requires a valid configuration. It can be set using environmental variables in your system or IDE, or by sourcing an `.env` file.
Refer to the example config found in [integration_tests.env.example](integration_tests.env.example).
Please note that while there are publicly accessible gateway URLs, you will additionally need a `RPC node URL` and an `account address` (along with its `private key`), to run these tests.

Integration tests are disabled by default. To enable them, you can set the env variable:
```env
INTEGRATION_TEST_MODE=non_gas
```
Some of integration tests require gas and are disabled by default. If you want to run them as well, you can set:
```env
INTEGRATION_TEST_MODE=all
```
Please be aware that in that case your integration account address must have a pre-existing balance as these tests will consume some funds.

Alternatively, you can use flag to specify whether to run integration and gas tests:
```shell
./gradlew :lib:test -PintegrationTestMode=non_gas
./gradlew :lib:test -PintegrationTestMode=all
```
Flag takes precendece over the env variable if both are set.

### Ensuring idiomatic Java code
We want this library to be used by both kotlin & java users. In order to ensure a nice API for java always follow those rules:
Expand Down
6 changes: 6 additions & 0 deletions integration_tests.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INTEGRATION_TEST_MODE=disabled
INTEGRATION_RPC_URL=http://example-node-url.com/rpc
INTEGRATION_GATEWAY_URL=http://example.com/gateway
INTEGRATION_FEEDER_GATEWAY_URL=http://example.com/feeder_gateway
INTEGRATION_PRIVATE_KEY=0x123456789
INTEGRATION_ACCOUNT_ADDRESS=0x123456789123456789123456789123456789123456789123456789123456789
6 changes: 6 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ tasks.test {
val poseidonPath = file("${rootDir}/crypto/poseidon/build/bindings").absolutePath

systemProperty("java.library.path", "$libsSharedPath:$pedersenPath:$poseidonPath")
systemProperty(
"integrationTestMode",
project.findProperty("integrationTestMode")
?: System.getenv("INTEGRATION_TEST_MODE")
?: "disabled",
)

maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonObject

internal object JsonRpcGetBlockWithTransactionsPolymorphicSerializer : JsonContentPolymorphicSerializer<GetBlockWithTransactionsResponse>(GetBlockWithTransactionsResponse::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out GetBlockWithTransactionsResponse> =
when (element.jsonObject["status"]) {
null -> PendingBlockWithTransactionsResponse.serializer()
else -> BlockWithTransactionsResponse.serializer()
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out GetBlockWithTransactionsResponse> {
val isPendingBlock = listOf("block_hash", "block_number", "new_root").any { it !in element.jsonObject }

return when (isPendingBlock) {
true -> PendingBlockWithTransactionsResponse.serializer()
false -> BlockWithTransactionsResponse.serializer()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ internal object JsonRpcTransactionReceiptPolymorphicSerializer :
JsonContentPolymorphicSerializer<TransactionReceipt>(TransactionReceipt::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out TransactionReceipt> {
val jsonElement = element.jsonObject
val isPending = "status" !in jsonElement
return if (isPending) selectPendingDeserializer(jsonElement) else selectDeserializer(jsonElement)
val isPendingTransactionReceipt = listOf("block_hash", "block_number").any { it !in jsonElement }

return when (isPendingTransactionReceipt) {
true -> selectPendingDeserializer(jsonElement)
false -> selectDeserializer(jsonElement)
}
}

private fun selectPendingDeserializer(element: JsonObject): DeserializationStrategy<out TransactionReceipt> =
when {
"contract_address" in element -> PendingRpcDeployTransactionReceipt.serializer()
else -> PendingRpcTransactionReceipt.serializer()
private fun selectPendingDeserializer(element: JsonObject): DeserializationStrategy<out TransactionReceipt> {
val isDeployTransactionReceipt = "contract_address" in element

return when (isDeployTransactionReceipt) {
true -> PendingRpcDeployTransactionReceipt.serializer()
false -> PendingRpcTransactionReceipt.serializer()
}
}

private fun selectDeserializer(element: JsonObject): DeserializationStrategy<out TransactionReceipt> =
when (element["type"]?.jsonPrimitive?.content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ internal object TransactionPolymorphicSerializer : JsonContentPolymorphicSeriali

private fun selectDeclareDeserializer(element: JsonElement): DeserializationStrategy<out DeclareTransaction> =
when (element.jsonObject["version"]?.jsonPrimitive?.content) {
Felt.ZERO.hexString() -> DeclareTransactionV0.serializer()
Felt.ONE.hexString() -> DeclareTransactionV1.serializer()
Felt(2).hexString() -> DeclareTransactionV2.serializer()
else -> throw IllegalArgumentException("Invalid invoke transaction version '${element.jsonObject["version"]?.jsonPrimitive?.content}'")
else -> throw IllegalArgumentException("Invalid declare transaction version '${element.jsonObject["version"]?.jsonPrimitive?.content}'")
}
}
39 changes: 17 additions & 22 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Messages.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
package com.swmansion.starknet.data.types

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames

@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class GatewayMessageL2ToL1(
@JsonNames("to_address")
val toAddress: Felt,

@JsonNames("payload")
val payload: List<Felt>,
)

@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class GatewayMessageL1ToL2(
@JsonNames("from_address")
val fromAddress: Felt,

@JsonNames("payload")
val payload: List<Felt>,
)

@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class RpcMessageL2ToL1(
data class MessageL2ToL1(
@JsonNames("from_address")
@SerialName("from_address")
val fromAddress: Felt,

@JsonNames("to_address")
@SerialName("to_address")
val toAddress: Felt,

@JsonNames("payload")
@SerialName("payload")
val payload: List<Felt>,
)

@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class RpcMessageL1ToL2(
data class MessageL1ToL2(
@JsonNames("from_address")
@SerialName("from_address")
val fromAddress: Felt,

@JsonNames("to_address")
@SerialName("to_address")
val toAddress: Felt,

@JsonNames("selector", "entry_point_selector")
@SerialName("entry_point_selector")
val selector: Felt,

@JsonNames("nonce")
@SerialName("nonce")
val nonce: Felt? = null,

@JsonNames("payload")
@SerialName("payload")
val payload: List<Felt>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ data class EstimateTransactionFeePayload(
@Serializable
data class EstimateMessageFeePayload(
@SerialName("message")
val message: Call,

@SerialName("sender_address")
val senderAddress: Felt,
val message: MessageL1ToL2,

@SerialName("block_id")
override val blockId: BlockId,
Expand Down
27 changes: 20 additions & 7 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Responses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ data class BlockWithTransactionsResponse(
@SerialName("status")
val status: BlockStatus,

// Block header

@SerialName("parent_hash")
override val parentHash: Felt,
THenry14 marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -147,35 +149,46 @@ data class BlockWithTransactionsResponse(
@SerialName("new_root")
val newRoot: Felt,

@SerialName("timestamp")
override val timestamp: Int,

@SerialName("sequencer_address")
override val sequencerAddress: Felt,

// Block body

DelevoXDG marked this conversation as resolved.
Show resolved Hide resolved
@SerialName("transactions")
override val transactions: List<
@Serializable(with = TransactionPolymorphicSerializer::class)
Transaction,
>,

@SerialName("timestamp")
override val timestamp: Int,

@SerialName("sequencer_address")
override val sequencerAddress: Felt,
) : GetBlockWithTransactionsResponse()

@Serializable
data class PendingBlockWithTransactionsResponse(
@SerialName("parent_hash")
override val parentHash: Felt,
// Not in RPC schema
@SerialName("status")
val status: BlockStatus = BlockStatus.PENDING,

// Block body

@SerialName("transactions")
override val transactions: List<
@Serializable(with = TransactionPolymorphicSerializer::class)
Transaction,
>,

// Block info

@SerialName("timestamp")
override val timestamp: Int,

@SerialName("sequencer_address")
override val sequencerAddress: Felt,

@SerialName("parent_hash")
override val parentHash: Felt,
) : GetBlockWithTransactionsResponse()

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.swmansion.starknet.data.types.Calldata
import com.swmansion.starknet.data.types.EstimateFeeResponse
import com.swmansion.starknet.data.types.EventContent
import com.swmansion.starknet.data.types.Felt
import com.swmansion.starknet.data.types.RpcMessageL2ToL1
import com.swmansion.starknet.data.types.MessageL2ToL1
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -61,7 +61,7 @@ data class FunctionInvocation(
val events: List<EventContent>?,

@SerialName("messages")
val messages: List<RpcMessageL2ToL1>?,
val messages: List<MessageL2ToL1>?,
)

@Serializable
Expand Down
Loading