Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters:
- errcheck

run:
go: '1.22'
go: '1.25'

issues:
exclude-rules:
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Dune Analytics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ A command-line interface for interacting with the Dune Analytics API.
# Save your API key to ~/.config/dune/config.yaml
dune auth --api-key <key>

# Or run interactively (prompts for key)
dune auth

# Or set via environment variable
export DUNE_API_KEY=<key>
```
Expand All @@ -26,16 +29,16 @@ Manage and execute Dune queries.
| `query get <query-id>` | Get a saved query's details and SQL |
| `query update <query-id> [--name] [--sql] [--description] [--private] [--tags]` | Update an existing query |
| `query archive <query-id>` | Archive a saved query |
| `query run <query-id> [--param key=value] [--performance medium\|large] [--limit] [--no-wait]` | Execute a saved query and display results |
| `query run-sql --sql <sql> [--param key=value] [--performance medium\|large] [--limit] [--no-wait]` | Execute raw SQL directly |
| `query run <query-id> [--param key=value] [--performance medium\|large] [--limit] [--timeout] [--no-wait]` | Execute a saved query and display results |
| `query run-sql --sql <sql> [--param key=value] [--performance medium\|large] [--limit] [--timeout] [--no-wait]` | Execute raw SQL directly |

### `dune execution`

Manage query executions.

| Command | Description |
|---------|-------------|
| `execution results <execution-id> [--limit] [--offset]` | Fetch results of a query execution |
| `execution results <execution-id> [--limit] [--offset] [--timeout] [--no-wait]` | Fetch results of a query execution |

### `dune dataset`

Expand All @@ -44,6 +47,7 @@ Search the Dune dataset catalog.
| Command | Description |
|---------|-------------|
| `dataset search [--query] [--categories] [--blockchains] [--schemas] [--dataset-types] [--owner-scope] [--include-private] [--include-schema] [--include-metadata] [--limit] [--offset]` | Search for datasets |
| `dataset search-by-contract --contract-address <address> [--blockchains] [--include-schema] [--limit] [--offset]` | Search for decoded tables by contract address |

Categories: `canonical`, `decoded`, `spell`, `community`

Expand All @@ -65,4 +69,4 @@ dune usage [--start-date YYYY-MM-DD] [--end-date YYYY-MM-DD]

## Output Format

Most commands support `-o, --output <format>` with `text` (default) or `json`.
All commands (except `auth`) support `-o, --output <format>` with `text` (default) or `json`.
130 changes: 130 additions & 0 deletions cmd/dataset/search_by_contract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package dataset_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/duneanalytics/duneapi-client-go/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSearchByContractSuccess(t *testing.T) {
dt := "decoded"
var gotReq models.SearchDatasetsByContractAddressRequest

mock := &mockClient{
searchByContractAddressFn: func(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error) {
gotReq = req
return &models.SearchDatasetsResponse{
Total: 2,
Results: []models.SearchDatasetResult{
{
FullName: "uniswap_v3_ethereum.UniswapV3Factory_evt_PoolCreated",
Category: "decoded",
DatasetType: &dt,
Blockchains: []string{"ethereum"},
},
{
FullName: "uniswap_v3_ethereum.UniswapV3Factory_call_createPool",
Category: "decoded",
DatasetType: &dt,
Blockchains: []string{"ethereum"},
},
},
Pagination: models.SearchDatasetsPagination{
Limit: 20,
Offset: 0,
HasMore: false,
},
}, nil
},
}

root, buf := newTestRoot(mock)
root.SetArgs([]string{
"dataset", "search-by-contract",
"--contract-address", "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"--blockchains", "ethereum",
"--limit", "10",
})

require.NoError(t, root.Execute())

// Verify flags mapped to request
assert.Equal(t, "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", gotReq.ContractAddress)
assert.Equal(t, []string{"ethereum"}, gotReq.Blockchains)
assert.Equal(t, int32(10), *gotReq.Limit)

// Verify table output
out := buf.String()
assert.Contains(t, out, "uniswap_v3_ethereum.UniswapV3Factory_evt_PoolCreated")
assert.Contains(t, out, "uniswap_v3_ethereum.UniswapV3Factory_call_createPool")
assert.Contains(t, out, "decoded")
assert.Contains(t, out, "2 of 2 results")
}

func TestSearchByContractJSON(t *testing.T) {
mock := &mockClient{
searchByContractAddressFn: func(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error) {
return &models.SearchDatasetsResponse{
Total: 1,
Results: []models.SearchDatasetResult{
{
FullName: "uniswap_v3_ethereum.UniswapV3Factory_evt_PoolCreated",
Category: "decoded",
},
},
Pagination: models.SearchDatasetsPagination{
Limit: 20,
Offset: 0,
HasMore: false,
},
}, nil
},
}

root, buf := newTestRoot(mock)
root.SetArgs([]string{
"dataset", "search-by-contract",
"--contract-address", "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"-o", "json",
})

require.NoError(t, root.Execute())

var resp models.SearchDatasetsResponse
require.NoError(t, json.Unmarshal(buf.Bytes(), &resp))
assert.Equal(t, int32(1), resp.Total)
assert.Equal(t, "uniswap_v3_ethereum.UniswapV3Factory_evt_PoolCreated", resp.Results[0].FullName)
}

func TestSearchByContractError(t *testing.T) {
mock := &mockClient{
searchByContractAddressFn: func(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error) {
return nil, fmt.Errorf("API error: unauthorized")
},
}

root, _ := newTestRoot(mock)
root.SetArgs([]string{
"dataset", "search-by-contract",
"--contract-address", "0xdeadbeef",
})

err := root.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "API error: unauthorized")
}

func TestSearchByContractRequiresAddress(t *testing.T) {
mock := &mockClient{}

root, _ := newTestRoot(mock)
root.SetArgs([]string{"dataset", "search-by-contract"})

err := root.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "contract-address")
}
7 changes: 6 additions & 1 deletion cmd/dataset/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ import (

type mockClient struct {
dune.DuneClient
searchDatasetsFn func(models.SearchDatasetsRequest) (*models.SearchDatasetsResponse, error)
searchDatasetsFn func(models.SearchDatasetsRequest) (*models.SearchDatasetsResponse, error)
searchByContractAddressFn func(models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error)
}

func (m *mockClient) SearchDatasets(req models.SearchDatasetsRequest) (*models.SearchDatasetsResponse, error) {
return m.searchDatasetsFn(req)
}

func (m *mockClient) SearchDatasetsByContractAddress(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error) {
return m.searchByContractAddressFn(req)
}

func newTestRoot(mock dune.DuneClient) (*cobra.Command, *bytes.Buffer) {
root := &cobra.Command{
Use: "dune",
Expand Down
Loading