github.com/ethereum-optimism/optimism/l2geth@v0.0.0-20230612200230-50b04ade19e3/rollup/client_test.go (about) 1 package rollup 2 3 import ( 4 "encoding/json" 5 "errors" 6 "fmt" 7 "math/big" 8 "testing" 9 10 "github.com/jarcoal/httpmock" 11 ) 12 13 const url = "http://localhost:9999" 14 15 func TestRollupClientCannotConnect(t *testing.T) { 16 endpoint := fmt.Sprintf("%s/eth/context/latest", url) 17 client := NewClient(url, big.NewInt(1)) 18 19 httpmock.ActivateNonDefault(client.client.GetClient()) 20 21 response, _ := httpmock.NewJsonResponder( 22 400, 23 map[string]interface{}{}, 24 ) 25 httpmock.RegisterResponder( 26 "GET", 27 endpoint, 28 response, 29 ) 30 31 context, err := client.GetLatestEthContext() 32 if context != nil { 33 t.Fatal("returned value is not nil") 34 } 35 if !errors.Is(err, errHTTPError) { 36 t.Fatalf("Incorrect error returned: %s", err) 37 } 38 } 39 func TestDecodedJSON(t *testing.T) { 40 str := []byte(` 41 { 42 "index": 643116, 43 "batchIndex": 21083, 44 "blockNumber": 25954867, 45 "timestamp": 1625605288, 46 "gasLimit": "11000000", 47 "target": "0x4200000000000000000000000000000000000005", 48 "origin": null, 49 "data": "0xf86d0283e4e1c08343eab8941a5245ea5210c3b57b7cfdf965990e63534a7b528901a055690d9db800008081aea019f7c6719f1718475f39fb9e5a6a897c3bd5057488a014666e5ad573ec71cf0fa008836030e686f3175dd7beb8350809b47791c23a19092a8c2fab1f0b4211a466", 50 "queueOrigin": "sequencer", 51 "value": "0x1a055690d9db80000", 52 "queueIndex": null, 53 "decoded": { 54 "nonce": "2", 55 "gasPrice": "15000000", 56 "gasLimit": "4451000", 57 "value": "0x1a055690d9db80000", 58 "target": "0x1a5245ea5210c3b57b7cfdf965990e63534a7b52", 59 "data": "0x", 60 "sig": { 61 "v": 1, 62 "r": "0x19f7c6719f1718475f39fb9e5a6a897c3bd5057488a014666e5ad573ec71cf0f", 63 "s": "0x08836030e686f3175dd7beb8350809b47791c23a19092a8c2fab1f0b4211a466" 64 } 65 }, 66 "confirmed": true 67 }`) 68 69 tx := new(transaction) 70 json.Unmarshal(str, tx) 71 cmp, _ := new(big.Int).SetString("1a055690d9db80000", 16) 72 if tx.Value.ToInt().Cmp(cmp) != 0 { 73 t.Fatal("Cannot decode") 74 } 75 }