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

Add /construction/preprocess tests #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ run-optimism-goerli-data-check:
run-optimism-goerli-construction-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:construction configs/optimism/goerli.json

# Runs the rosetta-cli check:construction command with the optimism goerli configuration
run-optimism-goerli-erc20-construction-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli-erc20.json rosetta-cli check:construction configs/optimism/goerli.json


# Runs an instance of `op-rosetta` configured for Optimism Goerli
# For the genesis block hash, see:
# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go#L49
Expand Down
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-erc20.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
184 changes: 184 additions & 0 deletions test/construction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package test

import (
"context"
"encoding/json"
"testing"

config "github.com/mdehoog/op-rosetta/pkg/config"
utils "github.com/mdehoog/op-rosetta/pkg/utils"

RosettaConfiguration "github.com/coinbase/rosetta-geth-sdk/configuration"
RosettaConstruction "github.com/coinbase/rosetta-geth-sdk/services/construction"
RosettaGethTypes "github.com/coinbase/rosetta-geth-sdk/types"
RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"
EthParams "github.com/ethereum/go-ethereum/params"
assert "github.com/stretchr/testify/assert"
)

func TestPreprocessERC20(t *testing.T) {
networkID := &RosettaTypes.NetworkIdentifier{
Blockchain: config.DefaultBlockchain,
Network: "testnet",
}
cfg := &RosettaConfiguration.Configuration{
Mode: RosettaConfiguration.ModeOnline,
Network: networkID,
ChainConfig: EthParams.TestChainConfig,
}
servicer := RosettaConstruction.NewAPIService(cfg, utils.LoadTypes(), RosettaGethTypes.Errors, nil)
ctx := context.Background()

intent := `
[
{
"operation_identifier": {
"index":0
},
"type":"PAYMENT",
"account": {
"address":"0x9670d6977d0b10130E5d4916c9134363281B6B0e"
},
"amount": {
"value":"-100000000000",
"currency":{
"symbol":"OP",
"decimals":18,
"metadata":{
"token_address":"0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A"
}
}
}
},
{
"operation_identifier": {
"index":1
},
"type":"PAYMENT",
"account": {
"address":"0x705f9aE78b11a3ED5080c053Fa4Fa0c52359c674"
},
"amount": {
"value":"100000000000",
"currency": {
"symbol":"OP",
"decimals":18,
"metadata": {
"token_address":"0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A"
}
}
}
}
]
`
var ops []*RosettaTypes.Operation
assert.NoError(t, json.Unmarshal([]byte(intent), &ops))
preprocessResponse, err := servicer.ConstructionPreprocess(
ctx,
&RosettaTypes.ConstructionPreprocessRequest{
NetworkIdentifier: networkID,
Operations: ops,
},
)
assert.Nil(t, err)
options := map[string]interface{}{
"from": "0x9670d6977d0b10130E5d4916c9134363281B6B0e",
"to": "0x705f9aE78b11a3ED5080c053Fa4Fa0c52359c674",
"value": "0x0",
"currency": map[string]interface{}{
"decimals": float64(18),
"symbol": "OP",
"metadata": map[string]interface{}{
"contractAddress": "0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A",
},
},
}
assert.Equal(t, &RosettaTypes.ConstructionPreprocessResponse{
Options: options,
}, preprocessResponse)
}

func TestPreprocessGovernanceDelegate(t *testing.T) {
networkID := &RosettaTypes.NetworkIdentifier{
Blockchain: config.DefaultBlockchain,
Network: "testnet",
}
cfg := &RosettaConfiguration.Configuration{
Mode: RosettaConfiguration.ModeOnline,
Network: networkID,
ChainConfig: EthParams.TestChainConfig,
}
servicer := RosettaConstruction.NewAPIService(cfg, utils.LoadTypes(), RosettaGethTypes.Errors, nil)
ctx := context.Background()

intent := `
[
{
"operation_identifier": {
"index": 0
},
"type": "DELEGATE_VOTES",
"account": {
"address": "0x9670d6977d0b10130E5d4916c9134363281B6B0e"
},
"amount": {
"value": "0",
"currency": {
"symbol": "OP",
"decimals": 18,
"metadata": {
"token_address": "0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A"
}
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "DELEGATE_VOTES",
"account": {
"address": "0x705f9aE78b11a3ED5080c053Fa4Fa0c52359c674"
},
"amount": {
"value": "0",
"currency": {
"symbol": "OP",
"decimals": 18,
"metadata": {
"token_address": "0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A"
}
}
}
}
]
`

var ops []*RosettaTypes.Operation
assert.NoError(t, json.Unmarshal([]byte(intent), &ops))
preprocessResponse, err := servicer.ConstructionPreprocess(
ctx,
&RosettaTypes.ConstructionPreprocessRequest{
NetworkIdentifier: networkID,
Operations: ops,
},
)
assert.Nil(t, err)
methodArgs := []interface{}{"0x705f9aE78b11a3ED5080c053Fa4Fa0c52359c674"}
options := map[string]interface{}{
"from": "0x9670d6977d0b10130E5d4916c9134363281B6B0e",
"to": "0x705f9aE78b11a3ED5080c053Fa4Fa0c52359c674",
"value": "0x0",
"contract_address": "0xF8B089026CaD7DDD8CB8d79036A1ff1d4233d64A",
"data": "0x5c19a95c000000000000000000000000705f9aE78b11a3ED5080c053Fa4Fa0c52359c674",
"method_signature": "delegate(address)",
"method_args": methodArgs,
"currency": map[string]interface{}{
"decimals": float64(18),
"symbol": "OP",
},
}
assert.Equal(t, &RosettaTypes.ConstructionPreprocessResponse{
Options: options,
}, preprocessResponse)
}
13 changes: 13 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Package test contains larger-scoped tests surrounding op-rosetta and it's dependencies.
package test

import (
RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"
)

var (
OPCurrency = &RosettaTypes.Currency{
Symbol: "OP",
Decimals: 18,
}
)