Skip to content

Commit

Permalink
Added Test for GetTxReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
avislash committed Oct 15, 2021
1 parent 05760e6 commit db1de1b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module github.com/nanmu42/etherscan-api

go 1.13

require (
github.com/davecgh/go-spew v1.1.1
github.com/google/go-cmp v0.5.6
)
31 changes: 31 additions & 0 deletions proxy_e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2021 Avi Misra
*
* Use of this work is governed by a MIT License.
* You may find a license copy in project root.
*/

package etherscan

import (
"encoding/json"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/google/go-cmp/cmp"
)

func TestClient_GetTransactionReceipt(t *testing.T) {
var expectedReceipt TxReceipt
//Response grabbed from random transaction on Etherscan.io. This is a good test since it has a couple of embedded Logs
cannedResp := []byte(`{"blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","blockNumber":"0xccc210","contractAddress":null,"cumulativeGasUsed":"0x35365c","effectiveGasPrice":"0x26d7dd3724","from":"0xf878c632317b5c58c88e8b7e8de6aa17bb3dfe83","gasUsed":"0x200ea","logs":[{"address":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","topics":["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c","0x00000000000000000000000003f7724180aa6b939894b5ca4314783b0b36b329"],"data":"0x000000000000000000000000000000000000000000000000008e1bc9bf040000","blockNumber":"0xccc210","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","logIndex":"0x37","removed":false},{"address":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000003f7724180aa6b939894b5ca4314783b0b36b329","0x000000000000000000000000d0dcb7a4f8cfcdb29364d621ca5d997b7eddbc46"],"data":"0x000000000000000000000000000000000000000000000000008e1bc9bf040000","blockNumber":"0xccc210","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","logIndex":"0x38","removed":false},{"address":"0x8b3192f5eebd8579568a2ed41e6feb402f93f73f","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000d0dcb7a4f8cfcdb29364d621ca5d997b7eddbc46","0x000000000000000000000000f878c632317b5c58c88e8b7e8de6aa17bb3dfe83"],"data":"0x000000000000000000000000000000000000000000000000932a9ca104b8bd31","blockNumber":"0xccc210","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","logIndex":"0x39","removed":false},{"address":"0xd0dcb7a4f8cfcdb29364d621ca5d997b7eddbc46","topics":["0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"],"data":"0x0000000000000000000000000000000000000000000000f2ce932331c81806b2000000000000000000000000000000000000000000000000e5a3780b0117856d","blockNumber":"0xccc210","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","logIndex":"0x3a","removed":false},{"address":"0xd0dcb7a4f8cfcdb29364d621ca5d997b7eddbc46","topics":["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822","0x00000000000000000000000003f7724180aa6b939894b5ca4314783b0b36b329","0x000000000000000000000000f878c632317b5c58c88e8b7e8de6aa17bb3dfe83"],"data":"0x000000000000000000000000000000000000000000000000000008d0e801213b000000000000000000000000000000000000000000000000008e1bc9bf040000000000000000000000000000000000000000000000000000962b7b410a0ae0650000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0xccc210","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","blockHash":"0x9d4d4c6bab3dcd3b0b3a65f3b1880a9414990090da9315183b81a1b9a309b79e","logIndex":"0x3b","removed":false}],"logsBloom":"0x00200000000000000000000080000004000000000800000000000000000040000000000000000000000000000000000003000000080001000000000000000000000000000000000000000008000000200000000000000000000020008000000000000000000000000000000000000000000210000000000000000010000000000000000000000000100000000000000400000001000000080000004000000000000000000000000000000000000200000000001000000000000000000000000100000002001000000000000000000000000000000000001000000000000000000000200000000080000000000000000000000000000000400000000000000000","status":"0x1","to":"0x03f7724180aa6b939894b5ca4314783b0b36b329","transactionHash":"0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5","transactionIndex":"0x12","type":"0x2"}`)

json.Unmarshal(cannedResp, &expectedReceipt)

actualReceipt, err := api.GetTransactionReceipt("0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5")
noError(t, err, "api.GetTransactionReceipt")

if !cmp.Equal(expectedReceipt, actualReceipt) {
t.Errorf(`api.GetTransactionReceipt("0x162681c37d4e5db904b85a9953cbbe213e9631d5c928ad6b772f696aac9f67f5" not working, got %s, want %s`, spew.Sdump(actualReceipt), spew.Sdump(expectedReceipt))
}
}

0 comments on commit db1de1b

Please sign in to comment.