Skip to content

Commit

Permalink
add abiFetcher test
Browse files Browse the repository at this point in the history
  • Loading branch information
serichoi65 committed Feb 19, 2025
1 parent 9688145 commit dd4f27c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pkg/abiFetcher/abiFetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Layr-Labs/sidecar/internal/tests"
"github.com/Layr-Labs/sidecar/pkg/clients/ethereum"
"github.com/Layr-Labs/sidecar/pkg/postgres"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -50,8 +51,29 @@ func Test_AbiFetcher(t *testing.T) {

client := ethereum.NewClient(ethConfig, l)

t.Run("Test getting IPFS url from bytecode", func(t *testing.T) {
af := NewAbiFetcher(client, l)

address := "0x29a954e9e7f12936db89b183ecdf879fbbb99f14"
bytecode, err := af.EthereumClient.GetCode(context.Background(), address)
assert.Nil(t, err)

url, err := af.GetIPFSUrlFromBytecode(bytecode)
assert.Nil(t, err)

expectedUrl := "https://ipfs.io/ipfs/QmeuBk6fmBdgW3B3h11LRkFw8shYLbMb4w7ko82jCxg6jR"
assert.Equal(t, expectedUrl, url)
})
t.Run("Test fetching ABI from IPFS", func(t *testing.T) {
af := NewAbiFetcher(client, l)
_, _, _ = af.FetchMetadataFromAddress(context.Background(), "0x29a954e9e7f12936db89b183ecdf879fbbb99f14")

address := "0x29a954e9e7f12936db89b183ecdf879fbbb99f14"
bytecode, err := af.EthereumClient.GetCode(context.Background(), address)
assert.Nil(t, err)

abi, err := af.FetchAbiFromIPFS(address, bytecode)
assert.Nil(t, err)

assert.Greater(t, len(abi), 0)
})
}

0 comments on commit dd4f27c

Please sign in to comment.