Skip to content

Commit

Permalink
Merge pull request #7 from mdehoog/refcell/enhancements
Browse files Browse the repository at this point in the history
Feat: Handler Extensions and Testing
  • Loading branch information
refcell authored Jan 31, 2023
2 parents b63a9f8 + 62ac17a commit a33b348
Show file tree
Hide file tree
Showing 32 changed files with 1,858 additions and 595 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ OPTIMISM_GOERLI_NODE=
# Optimism Mainnet Node URL
OPTIMISM_MAINNET_NODE=

# Optimism Goerli Genesis Block Hash
OPTIMISM_GOERLI_GENESIS_BLOCK_HASH=

# Optimism Mainnet Genesis Block Hash
OPTIMISM_MAINNET_GENESIS_BLOCK_HASH=
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GOLINES_INSTALL=go install github.com/segmentio/golines@latest
GOLINES_CMD=golines

# Run the full pipeline
all: clean format build test lint
all: clean tidy format build test lint
.PHONY: \
test \
tests \
Expand All @@ -31,6 +31,10 @@ all: clean format build test lint
clean:
rm -rf bin/op-rosetta

# Tidy the go mod
tidy:
go mod tidy

# Formatting with gofmt
format:
gofmt -s -w -l .
Expand Down Expand Up @@ -87,7 +91,7 @@ run-optimism-goerli:
GETH=${OPTIMISM_GOERLI_NODE} \
ENABLE_TRACE_CACHE=true \
ENABLE_GETH_TRACER=true \
GENESIS_BLOCK_HASH=0x0f783549ea4313b784eadd9b8e8a69913b368b7366363ea814d7707ac505175f \
GENESIS_BLOCK_HASH=${OPTIMISM_GOERLI_GENESIS_BLOCK_HASH} \
bin/op-rosetta

#####################################################################################
Expand All @@ -106,7 +110,6 @@ run-optimism-mainnet-data-check:
run-optimism-mainnet-construction-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:construction configs/optimism/mainnet.json

# TODO: Set the GENESIS_BLOCK_HASH value for this command
# Runs an instance of `op-rosetta` configured for Optimism Mainnet
# For the genesis block hash, see:
# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go
Expand All @@ -120,6 +123,6 @@ run-optimism-mainnet:
ENABLE_TRACE_CACHE=true \
ENABLE_GETH_TRACER=true \
GETH=${OPTIMISM_MAINNET_NODE} \
GENESIS_BLOCK_HASH= \
GENESIS_BLOCK_HASH=${OPTIMISM_MAINNET_GENESIS_BLOCK_HASH} \
bin/op-rosetta

38 changes: 38 additions & 0 deletions configs/optimism/goerli-basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"network": {
"blockchain": "Optimism",
"network": "Goerli",
"sub_network_identifier": null
},
"online_url": "http://localhost:8080",
"data_directory": "",
"http_timeout": 300,
"max_retries": 100,
"max_online_connections": 500,
"force_retry": true,
"max_sync_concurrency": 64,
"tip_delay": 120,
"max_reorg_depth": 64,
"log_configuration": false,
"compression_disabled": true,
"l0_in_memory_enabled": true,
"all_in_memory_enabled": true,
"table_size": 1,
"value_log_file_size": 1024,
"construction": null,
"data": {
"start_index": 4307133,
"reconciliation_disabled": true,
"inactive_discrepancy_search_disabled": true,
"balance_tracking_disabled": true,
"initial_balance_fetch_disabled":true,
"active_reconciliation_concurrency": 32,
"bootstrap_balances": "",
"log_balance_changes": true,
"log_transactions": true,
"log_blocks": true,
"end_conditions": {
"tip": true
}
}
}
21 changes: 17 additions & 4 deletions configs/optimism/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@
"all_in_memory_enabled": true,
"table_size": 1,
"value_log_file_size": 1024,
"construction": null,
"construction": {
"stale_depth": 3,
"broadcast_limit": 5,
"ignore_broadcast_failures": false,
"clear_broadcasts": true,
"constructor_dsl_file": "goerli.ros",
"quiet": false,
"initial_balance_fetch_disabled": false,
"end_conditions": {
"create_account": 10,
"transfer": 20
}
},
"data": {
"start_index": 4307133,
"reconciliation_disabled": true,
"reconciliation_disabled": false,
"inactive_discrepancy_search_disabled": true,
"balance_tracking_disabled": true,
"initial_balance_fetch_disabled":true,
"balance_tracking_disabled": false,
"initial_balance_fetch_disabled": false,
"active_reconciliation_concurrency": 32,
"historical_balance_disabled": false,
"bootstrap_balances": "",
"log_balance_changes": true,
"log_transactions": true,
Expand Down
137 changes: 137 additions & 0 deletions configs/optimism/goerli.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
request_funds(1){
find_account{
currency = {"symbol":"ETH", "decimals":18};
random_account = find_balance({
"minimum_balance":{
"value": "0",
"currency": {{currency}}
},
"create_limit":1
});
},

// Create a separate scenario to request funds so that
// the address we are using to request funds does not
// get rolled back if funds do not yet exist.
request{
loaded_account = find_balance({
"account_identifier": {{random_account.account_identifier}},
"minimum_balance":{
"value": "10000000000000",
"currency": {{currency}}
}
});
}
}

create_account(1){
create{
network = {"network":"Goerli", "blockchain":"Optimism"};
key = generate_key({"curve_type": "secp256k1"});
account = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});

// If the account is not saved, the key will be lost!
save_account({
"account_identifier": {{account.account_identifier}},
"keypair": {{key}}
});
}
}

transfer(1){
transfer{
transfer.network = {"network":"Goerli", "blockchain":"Optimism"};
currency = {"symbol":"ETH", "decimals":18};
sender = find_balance({
"minimum_balance":{
"value": "10000000000000",
"currency": {{currency}}
}
});

// Set the recipient_amount as some value <= sender.balance-max_fee
max_fee = "0";
available_amount = {{sender.balance.value}} - {{max_fee}};
recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}});
print_message({"recipient_amount":{{recipient_amount}}});

// Find recipient and construct operations
sender_amount = 0 - {{recipient_amount}};
recipient = find_balance({
"not_account_identifier":[{{sender.account_identifier}}],
"minimum_balance":{
"value": "0",
"currency": {{currency}}
},
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{currency}}
}
}
];
}
}

return_funds(1){
transfer{
transfer.network = {"network":"Goerli", "blockchain":"Optimism"};
currency = {"symbol":"ETH", "decimals":18};
max_fee = "0";
sender = find_balance({
"minimum_balance":{
"value": {{max_fee}},
"currency": {{currency}}
}
});

// Set the recipient_amount as some sender.balance-max_fee
available_amount = {{sender.balance.value}} - {{max_fee}};
print_message({"available_amount":{{available_amount}}});
sender_amount = 0 - {{available_amount}};

// Provide a static address as the recipient and construct operations
faucet = {"address":"0xb41B39479a525AB69e38c701A713D98E3074252c"};
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{faucet}},
"amount":{
"value":{{available_amount}},
"currency":{{currency}}
}
}
];
}
}
111 changes: 111 additions & 0 deletions configs/optimism/optimism.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
create_account(1){
create{
network = {"network":"Goerli", "blockchain":"Optimism"};
key = generate_key({"curve_type": "secp256k1"});
account = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});

// If the account is not saved, the key will be lost!
save_account({
"account_identifier": {{account.account_identifier}},
"keypair": {{key}}
});
}
}

transfer(10){
transfer{
transfer.network = {"network":"Goerli", "blockchain":"Optimism"};
currency = {"symbol":"ETH", "decimals":18};
sender = find_balance({
"minimum_balance":{
"value": "10000000000000000",
"currency": {{currency}}
}
});

// Set the recipient_amount as some value <= sender.balance-max_fee
max_fee = "84000000000000";
available_amount = {{sender.balance.value}} - {{max_fee}};
recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}});
print_message({"recipient_amount":{{recipient_amount}}});

// Find recipient and construct operations
sender_amount = 0 - {{recipient_amount}};
recipient = find_balance({
"not_account_identifier":[{{sender.account_identifier}}],
"minimum_balance":{
"value": "0",
"currency": {{currency}}
},
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{currency}}
}
}
];
}
}

return_funds(10){
transfer{
transfer.network = {"network":"Goerli", "blockchain":"Optimism"};
currency = {"symbol":"ETH", "decimals":18};
max_fee = "84000000000000";
sender = find_balance({
"minimum_balance":{
"value": {{max_fee}},
"currency": {{currency}}
}
});

// Set the recipient_amount as some sender.balance-max_fee
available_amount = {{sender.balance.value}} - {{max_fee}};
print_message({"available_amount":{{available_amount}}});
sender_amount = 0 - {{available_amount}};

// Provide a static address as the recipient and construct operations
faucet = {"address":"0x9670d6977d0b10130E5d4916c9134363281B6B0e"};
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{faucet}},
"amount":{
"value":{{available_amount}},
"currency":{{currency}}
}
}
];
}
}
Loading

0 comments on commit a33b348

Please sign in to comment.