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

rpcv06 update receipts #464

Merged
merged 6 commits into from
Nov 23, 2023
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
14 changes: 9 additions & 5 deletions rpc/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var (
base: "http://localhost:5050/rpc",
},
// Used with a mock as a standard configuration, see `mock_test.go``
"mock": {},
"mock": {},
"integration": {},
}
)

Expand All @@ -67,7 +68,8 @@ var (
// Parameters:
// - m: the testing.M struct
// Returns:
// none
//
// none
func TestMain(m *testing.M) {
flag.StringVar(&testEnv, "env", "mock", "set the test environment")
flag.Parse()
Expand All @@ -86,7 +88,7 @@ func beforeEach(t *testing.T) *testConfiguration {
godotenv.Load(fmt.Sprintf(".env.%s", testEnv), ".env")
testConfig, ok := testConfigurations[testEnv]
if !ok {
t.Fatal("env supports mock, testnet, mainnet or devnet")
t.Fatal("env supports mock, testnet, mainnet, devnet, integration")
}
if testEnv == "mock" {
testConfig.provider = &Provider{
Expand Down Expand Up @@ -122,7 +124,8 @@ func beforeEach(t *testing.T) *testConfiguration {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestChainID(t *testing.T) {
testConfig := beforeEach(t)

Expand Down Expand Up @@ -166,7 +169,8 @@ func TestChainID(t *testing.T) {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestSyncing(t *testing.T) {
testConfig := beforeEach(t)

Expand Down
87 changes: 72 additions & 15 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func TestTransactionByHash(t *testing.T) {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestTransactionByBlockIdAndIndex(t *testing.T) {
testConfig := beforeEach(t)

Expand Down Expand Up @@ -169,7 +170,8 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) {
testConfig := beforeEach(t)

Expand All @@ -179,7 +181,7 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) {
}
var receiptTxn310370_0 = InvokeTransactionReceipt(CommonTransactionReceipt{
TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"),
ActualFee: utils.TestHexToFelt(t, "0x1709a2f3a2"),
ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x1709a2f3a2"), Unit: UnitWei},
Type: "INVOKE",
ExecutionStatus: TxnExecutionStatusSUCCEEDED,
FinalityStatus: TxnFinalityStatusAcceptedOnL1,
Expand All @@ -206,6 +208,53 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) {
Keys: []*felt.Felt{utils.TestHexToFelt(t, "0xf806f71b19e4744968b37e3fb288e61309ab33a782ea9d11e18f67a1fbb110")},
},
},
ExecutionResources: ExecutionResources{
Steps: 217182,
MemoryHoles: 6644,
PedersenApps: 2142,
RangeCheckApps: 8867,
BitwiseApps: 900,
ECDSAApps: 1,
},
})

var receiptTxnIntegration = InvokeTransactionReceipt(CommonTransactionReceipt{
TransactionHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"),
ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x16d8b4ad4000"), Unit: UnitStrk},
Type: "INVOKE",
ExecutionStatus: TxnExecutionStatusSUCCEEDED,
FinalityStatus: TxnFinalityStatusAcceptedOnL2,
BlockHash: utils.TestHexToFelt(t, "0x50e864db6b81ce69fbeb70e6a7284ee2febbb9a2e707415de7adab83525e9cd"),
BlockNumber: 319132,
MessagesSent: []MsgToL1{},
Events: []Event{
{
FromAddress: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
Data: []*felt.Felt{
utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"),
utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"),
utils.TestHexToFelt(t, "0x16d8b4ad4000"),
utils.TestHexToFelt(t, "0x0"),
},
Keys: []*felt.Felt{utils.TestHexToFelt(t, "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9")},
},
{
FromAddress: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
Data: []*felt.Felt{
utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"),
utils.TestHexToFelt(t, "0x18ad8494375bc00"),
utils.TestHexToFelt(t, "0x0"),
utils.TestHexToFelt(t, "0x18aef21f822fc00"),
utils.TestHexToFelt(t, "0x0"),
},
Keys: []*felt.Felt{utils.TestHexToFelt(t, "0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd")},
},
},
ExecutionResources: ExecutionResources{
Steps: 615,
MemoryHoles: 4,
RangeCheckApps: 19,
},
})

testSet := map[string][]testSetType{
Expand All @@ -217,7 +266,12 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) {
},
},
"mainnet": {},
}[testEnv]
"integration": {
{
TxnHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"),
ExpectedTxnReceipt: receiptTxnIntegration,
},
}}[testEnv]

for _, test := range testSet {
spy := NewSpy(testConfig.provider.c)
Expand Down Expand Up @@ -252,7 +306,8 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestTransactionReceipt_MatchesStatus(t *testing.T) {
testConfig := beforeEach(t)

Expand Down Expand Up @@ -302,7 +357,8 @@ func TestTransactionReceipt_MatchesStatus(t *testing.T) {
// Parameters:
// - t: the testing object for running the test cases
// Returns:
// none
//
// none
func TestDeployOrDeclareReceipt(t *testing.T) {
testConfig := beforeEach(t)

Expand All @@ -313,15 +369,16 @@ func TestDeployOrDeclareReceipt(t *testing.T) {

var receiptTxn300114_3 = DeclareTransactionReceipt(
CommonTransactionReceipt{
TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"),
ActualFee: utils.TestHexToFelt(t, "0x0"),
FinalityStatus: TxnFinalityStatusAcceptedOnL1,
ExecutionStatus: TxnExecutionStatusSUCCEEDED,
BlockHash: utils.TestHexToFelt(t, "0x184268bfbce24766fa53b65c9c8b30b295e145e8281d543a015b46308e27fdf"),
BlockNumber: 300114,
Type: "DECLARE",
MessagesSent: []MsgToL1{},
Events: []Event{},
TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"),
ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x0"), Unit: UnitWei},
FinalityStatus: TxnFinalityStatusAcceptedOnL1,
ExecutionStatus: TxnExecutionStatusSUCCEEDED,
BlockHash: utils.TestHexToFelt(t, "0x184268bfbce24766fa53b65c9c8b30b295e145e8281d543a015b46308e27fdf"),
BlockNumber: 300114,
Type: "DECLARE",
MessagesSent: []MsgToL1{},
Events: []Event{},
ExecutionResources: ExecutionResources{Steps: 0},
})

testSet := map[string][]testSetType{
Expand Down
20 changes: 16 additions & 4 deletions rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ import (
"github.com/NethermindEth/juno/core/felt"
)

type FeePayment struct {
Amount *felt.Felt `json:"amount"`
Unit FeePaymentUnit `json:"unit"`
}

type FeePaymentUnit string

const (
UnitWei FeePaymentUnit = "WEI"
UnitStrk FeePaymentUnit = "STRK"
)

// CommonTransactionReceipt Common properties for a transaction receipt
type CommonTransactionReceipt struct {
// TransactionHash The hash identifying the transaction
TransactionHash *felt.Felt `json:"transaction_hash"`
// ActualFee The fee that was charged by the sequencer
ActualFee *felt.Felt `json:"actual_fee"`
ActualFee FeePayment `json:"actual_fee"`
ExecutionStatus TxnExecutionStatus `json:"execution_status"`
FinalityStatus TxnFinalityStatus `json:"finality_status"`
BlockHash *felt.Felt `json:"block_hash"`
Expand All @@ -22,7 +34,8 @@ type CommonTransactionReceipt struct {
MessagesSent []MsgToL1 `json:"messages_sent"`
RevertReason string `json:"revert_reason,omitempty"`
// Events The events emitted as part of this transaction
Events []Event `json:"events"`
Events []Event `json:"events"`
ExecutionResources ExecutionResources `json:"execution_resources"`
}

// Hash returns the transaction hash associated with the CommonTransactionReceipt.
Expand Down Expand Up @@ -350,8 +363,7 @@ type PendingCommonTransactionReceiptProperties struct {
// TransactionHash The hash identifying the transaction
TransactionHash *felt.Felt `json:"transaction_hash"`
// ActualFee The fee that was charged by the sequencer
ActualFee *felt.Felt `json:"actual_fee"`
Type TransactionType `json:"type,omitempty"`
ActualFee FeePayment `json:"actual_fee"`
MessagesSent []MsgToL1 `json:"messages_sent"`
ExecutionStatus TxnExecutionStatus `json:"execution_status"`
FinalityStatus TxnFinalityStatus `json:"finality_status"`
Expand Down
2 changes: 1 addition & 1 deletion rpc/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSpecVersion(t *testing.T) {
"mainnet": {},
"mock": {},
"testnet": {{
ExpectedResp: "0.5.0",
ExpectedResp: "0.6.0-rc1",
}},
}[testEnv]

Expand Down