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

Make actualFee nullable in GatewayProvider #187

Merged
merged 2 commits into from
Nov 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum class TransactionStatus {
@Serializable
sealed class TransactionReceipt {
abstract val hash: Felt
abstract val actualFee: Felt
abstract val actualFee: Felt?
abstract val isPending: Boolean
abstract val type: TransactionReceiptType
abstract val status: TransactionStatus
Expand Down Expand Up @@ -75,7 +75,7 @@ data class GatewayTransactionReceipt(
override val hash: Felt,

@JsonNames("actual_fee")
override val actualFee: Felt,
override val actualFee: Felt? = null,

@JsonNames("block_hash")
override val blockHash: Felt? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class StandardAccountTest {

val receipt = provider.getTransactionReceipt(result.transactionHash).send()

assertTrue(receipt.actualFee < maxFee)
assertTrue(receipt.actualFee!! < maxFee)
}

@ParameterizedTest
Expand Down
34 changes: 32 additions & 2 deletions lib/src/test/kotlin/starknet/provider/ProviderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class ProviderTest {

@Test
fun `get sync information node synced`() {
val mocked_response = """
val mockedResponse = """
{
"id": 0,
"jsonrpc": "2.0",
Expand All @@ -761,7 +761,7 @@ class ProviderTest {
}
""".trimIndent()
val httpService = mock<HttpService> {
on { send(any()) } doReturn HttpResponse(true, 200, mocked_response)
on { send(any()) } doReturn HttpResponse(true, 200, mockedResponse)
}
val provider = JsonRpcProvider(devnetClient.rpcUrl, StarknetChainId.TESTNET, httpService)
val request = provider.getSyncing()
Expand All @@ -776,4 +776,34 @@ class ProviderTest {
assertEquals(Felt.fromHex("0x10"), response.highestBlockHash)
assertEquals(10, response.highestBlockNumber)
}

@Test
fun `received gateway receipt`() {
val hash = Felt.fromHex("0x334da4f63cc6309ba2429a70f103872ab0ae82cf8d9a73b845184a4713cada5")
// There is no way for us to recreate this behaviour as devnet processes txs right away
val httpService = mock<HttpService> {
on { send(any()) } doReturn HttpResponse(
true,
200,
"""
{
"status": "RECEIVED",
"transaction_hash": "0x334da4f63cc6309ba2429a70f103872ab0ae82cf8d9a73b845184a4713cada5",
"l2_to_l1_messages": [],
"events": []
}
""".trimIndent(),
)
}
val provider = GatewayProvider.makeTestnetClient(httpService)
val receipt = provider.getTransactionReceipt(hash).send() as GatewayTransactionReceipt

assertEquals(hash, receipt.hash)
assertEquals(TransactionStatus.PENDING, receipt.status)
assertEquals(emptyList<MessageToL1>(), receipt.messagesToL1)
assertEquals(emptyList<Event>(), receipt.events)
assertNull(receipt.messageToL2)
assertNull(receipt.actualFee)
assertNull(receipt.failureReason)
}
}