Skip to content

Commit

Permalink
feat: tests overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jan 31, 2023
1 parent 54d8c30 commit 62ac17a
Show file tree
Hide file tree
Showing 12 changed files with 1,134 additions and 114 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

14 changes: 13 additions & 1 deletion configs/optimism/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
"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": false,
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}}
}
}
];
}
}
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ require (
)

require (
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/elastic/gosigar v0.12.0 // indirect
github.com/fjl/memsize v0.0.1 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/gomega v1.16.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand All @@ -31,7 +34,6 @@ require (
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/ethereum-optimism/optimism/l2geth v0.0.0-20230126221930-d11d4ad7b7df
github.com/fatih/color v1.13.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
Expand Down
Loading

0 comments on commit 62ac17a

Please sign in to comment.