2022-05-09 09:58:04 +02:00
|
|
|
package net
|
2022-05-08 13:13:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
2022-05-18 11:52:50 +02:00
|
|
|
|
|
|
|
"github.com/grassrootseconomics/cic-go/provider"
|
|
|
|
"github.com/lmittmann/w3"
|
2022-05-08 13:13:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCicNet_TokenIndex_EntryCount(t *testing.T) {
|
|
|
|
name := "Entry count"
|
|
|
|
wantErr := false
|
|
|
|
|
2022-05-18 11:52:50 +02:00
|
|
|
newProvider, err := provider.NewRpcProvider(conf.rpcProvider)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Creating an rpc instance failed = %v", err)
|
|
|
|
}
|
2022-05-18 12:41:55 +02:00
|
|
|
cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
|
2022-05-08 13:13:45 +02:00
|
|
|
|
2022-05-09 09:58:04 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewCicNet error = %v", err)
|
|
|
|
}
|
2022-05-08 13:13:45 +02:00
|
|
|
|
2022-05-09 09:58:04 +02:00
|
|
|
t.Run(name, func(t *testing.T) {
|
2022-05-18 11:52:50 +02:00
|
|
|
got, err := cicnet.EntryCount(context.Background())
|
2022-05-08 13:13:45 +02:00
|
|
|
|
|
|
|
if (err != nil) != wantErr {
|
|
|
|
t.Errorf("EntryCount() error = %v, wantErr %v", err, wantErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if got.Cmp(big.NewInt(0)) < 1 {
|
2022-05-09 09:58:04 +02:00
|
|
|
t.Errorf("EntryCount() = %v, want %v", got, 1)
|
2022-05-08 13:13:45 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCicNet_TokenIndex_AddressAtIndex(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
index *big.Int
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
address string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Address at index 0",
|
|
|
|
args: args{
|
|
|
|
index: big.NewInt(0),
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
address: "0xaB89822F31c2092861F713F6F34bd6877a8C1878",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Address at index 999",
|
|
|
|
args: args{
|
|
|
|
index: big.NewInt(999),
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
address: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-18 11:52:50 +02:00
|
|
|
newProvider, err := provider.NewRpcProvider(conf.rpcProvider)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Creating an rpc instance failed = %v", err)
|
|
|
|
}
|
2022-05-18 12:41:55 +02:00
|
|
|
cicnet, err := NewCicNet(newProvider, w3.A(conf.tokenIndex))
|
2022-05-09 09:58:04 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewCicNet error = %v", err)
|
|
|
|
}
|
|
|
|
|
2022-05-08 13:13:45 +02:00
|
|
|
for _, testcase := range tests {
|
|
|
|
tt := testcase
|
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-05-18 11:52:50 +02:00
|
|
|
got, err := cicnet.AddressAtIndex(context.Background(), tt.args.index)
|
2022-05-08 13:13:45 +02:00
|
|
|
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("AddressAtIndex() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if got != tt.address {
|
2022-05-09 09:58:04 +02:00
|
|
|
t.Errorf("AddressAtIndex = %v, want %v", got, tt.address)
|
2022-05-08 13:13:45 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|