Skip to content

Commit

Permalink
new tests for multiple web3 providers stuff and other tests updated w…
Browse files Browse the repository at this point in the history
…ith the test holders balances changes of test token
  • Loading branch information
lucasmenendez committed Oct 4, 2023
1 parent 4457bd3 commit 72d089c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
7 changes: 5 additions & 2 deletions census/census_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ var MonkeysAddresses = map[common.Address]*big.Int{
common.HexToAddress("0xe54d702f98E312aBA4318E3c6BDba98ab5e11012"): big.NewInt(16),
common.HexToAddress("0x38d2BC91B89928f78cBaB3e4b1949e28787eC7a3"): big.NewInt(13),
common.HexToAddress("0xF752B527E2ABA395D1Ba4C0dE9C147B763dDA1f4"): big.NewInt(12),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): big.NewInt(11),
common.HexToAddress("0xe1308a8d0291849bfFb200Be582cB6347FBE90D9"): big.NewInt(9),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): big.NewInt(6),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): big.NewInt(7),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): big.NewInt(5),
common.HexToAddress("0xF3C456FAAa70fea307A073C3DA9572413c77f58B"): big.NewInt(6),
common.HexToAddress("0x45D3a03E8302de659e7Ea7400C4cfe9CAED8c723"): big.NewInt(6),
common.HexToAddress("0x313c7f7126486fFefCaa9FEA92D968cbf891b80c"): big.NewInt(3),
common.HexToAddress("0x1893eD78480267D1854373A99Cee8dE2E08d430F"): big.NewInt(2),
common.HexToAddress("0xa2E4D94c5923A8dd99c5792A7B0436474c54e1E1"): big.NewInt(2),
common.HexToAddress("0x2a4636A5a1138e35F7f93e81FA56d3c970BC6777"): big.NewInt(1),
}

func TestNewCensusDB(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions service/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ var (
common.HexToAddress("0xe54d702f98E312aBA4318E3c6BDba98ab5e11012"): new(big.Int).SetUint64(16000000000000000000),
common.HexToAddress("0x38d2BC91B89928f78cBaB3e4b1949e28787eC7a3"): new(big.Int).SetUint64(13000000000000000000),
common.HexToAddress("0xF752B527E2ABA395D1Ba4C0dE9C147B763dDA1f4"): new(big.Int).SetUint64(12000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xe1308a8d0291849bfFb200Be582cB6347FBE90D9"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(7000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(5000000000000000000),
common.HexToAddress("0xF3C456FAAa70fea307A073C3DA9572413c77f58B"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x45D3a03E8302de659e7Ea7400C4cfe9CAED8c723"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x313c7f7126486fFefCaa9FEA92D968cbf891b80c"): new(big.Int).SetUint64(3000000000000000000),
common.HexToAddress("0x1893eD78480267D1854373A99Cee8dE2E08d430F"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0xa2E4D94c5923A8dd99c5792A7B0436474c54e1E1"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0x2a4636A5a1138e35F7f93e81FA56d3c970BC6777"): new(big.Int).SetUint64(1000000000000000000),
}
)

Expand Down
16 changes: 11 additions & 5 deletions state/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ var (
common.HexToAddress("0xe54d702f98E312aBA4318E3c6BDba98ab5e11012"): new(big.Int).SetUint64(16000000000000000000),
common.HexToAddress("0x38d2BC91B89928f78cBaB3e4b1949e28787eC7a3"): new(big.Int).SetUint64(13000000000000000000),
common.HexToAddress("0xF752B527E2ABA395D1Ba4C0dE9C147B763dDA1f4"): new(big.Int).SetUint64(12000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xe1308a8d0291849bfFb200Be582cB6347FBE90D9"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(7000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(5000000000000000000),
common.HexToAddress("0xF3C456FAAa70fea307A073C3DA9572413c77f58B"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x45D3a03E8302de659e7Ea7400C4cfe9CAED8c723"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x313c7f7126486fFefCaa9FEA92D968cbf891b80c"): new(big.Int).SetUint64(3000000000000000000),
common.HexToAddress("0x1893eD78480267D1854373A99Cee8dE2E08d430F"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0xa2E4D94c5923A8dd99c5792A7B0436474c54e1E1"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0x2a4636A5a1138e35F7f93e81FA56d3c970BC6777"): new(big.Int).SetUint64(1000000000000000000),
}
DefaultWeb3Provider = Web3Provider{

Check failure on line 31 in state/helper_test.go

View workflow job for this annotation

GitHub Actions / test

undefined: Web3Provider

Check failure on line 31 in state/helper_test.go

View workflow job for this annotation

GitHub Actions / test

undefined: Web3Provider
ChainID: 5,
Name: "Goerli",
ShortName: "gor",
URI: "https://eth-goerli.api.onfinality.io/public",
}
)

const defaultWeb3testUri = "https://eth-goerli.api.onfinality.io/public"

func web3testUri() string {
if uri := os.Getenv("WEB3_URI"); uri != "" {
return uri
}
return defaultWeb3testUri
return DefaultWeb3Provider.URI
}
47 changes: 47 additions & 0 deletions state/providers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package state

import (
"testing"

qt "github.com/frankban/quicktest"
)

func TestCheckWeb3Providers(t *testing.T) {
c := qt.New(t)

providers := []string{DefaultWeb3Provider.URI}
w3p, err := CheckWeb3Providers(providers)
c.Assert(err, qt.IsNil)
c.Assert(w3p[DefaultWeb3Provider.ChainID].URI, qt.Equals, DefaultWeb3Provider.URI)

Check failure on line 15 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].URI undefined (type string has no field or method URI)

Check failure on line 15 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].URI undefined (type string has no field or method URI)
c.Assert(w3p[DefaultWeb3Provider.ChainID].ShortName, qt.Equals, DefaultWeb3Provider.ShortName)

Check failure on line 16 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].ShortName undefined (type string has no field or method ShortName)

Check failure on line 16 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].ShortName undefined (type string has no field or method ShortName)
c.Assert(w3p[DefaultWeb3Provider.ChainID].Name, qt.Equals, DefaultWeb3Provider.Name)

Check failure on line 17 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].Name undefined (type string has no field or method Name)

Check failure on line 17 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p[DefaultWeb3Provider.ChainID].Name undefined (type string has no field or method Name)

t.Run("URIByChainID", func(t *testing.T) {
_, ok := w3p.URIByChainID(DefaultWeb3Provider.ChainID + 1)

Check failure on line 20 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.URIByChainID undefined (type map[uint64]string has no field or method URIByChainID)

Check failure on line 20 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.URIByChainID undefined (type map[uint64]string has no field or method URIByChainID)
c.Assert(ok, qt.IsFalse)
uri, ok := w3p.URIByChainID(DefaultWeb3Provider.ChainID)

Check failure on line 22 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.URIByChainID undefined (type map[uint64]string has no field or method URIByChainID)

Check failure on line 22 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.URIByChainID undefined (type map[uint64]string has no field or method URIByChainID)
c.Assert(ok, qt.Equals, true)
c.Assert(uri, qt.Equals, DefaultWeb3Provider.URI)
})
t.Run("ChainIDByShortName", func(t *testing.T) {
_, ok := w3p.ChainIDByShortName("UNKNOWN")

Check failure on line 27 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.ChainIDByShortName undefined (type map[uint64]string has no field or method ChainIDByShortName)

Check failure on line 27 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.ChainIDByShortName undefined (type map[uint64]string has no field or method ChainIDByShortName)
c.Assert(ok, qt.IsFalse)
chainID, ok := w3p.ChainIDByShortName(DefaultWeb3Provider.ShortName)

Check failure on line 29 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.ChainIDByShortName undefined (type map[uint64]string has no field or method ChainIDByShortName)

Check failure on line 29 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.ChainIDByShortName undefined (type map[uint64]string has no field or method ChainIDByShortName)
c.Assert(ok, qt.Equals, true)
c.Assert(chainID, qt.Equals, DefaultWeb3Provider.ChainID)
})
t.Run("PrefixBlockNumber", func(t *testing.T) {
_, ok := w3p.PrefixBlockNumber(DefaultWeb3Provider.ChainID+1, 123456)

Check failure on line 34 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.PrefixBlockNumber undefined (type map[uint64]string has no field or method PrefixBlockNumber)

Check failure on line 34 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.PrefixBlockNumber undefined (type map[uint64]string has no field or method PrefixBlockNumber)
c.Assert(ok, qt.IsFalse)
prefix, ok := w3p.PrefixBlockNumber(DefaultWeb3Provider.ChainID, 123456)

Check failure on line 36 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.PrefixBlockNumber undefined (type map[uint64]string has no field or method PrefixBlockNumber)

Check failure on line 36 in state/providers_test.go

View workflow job for this annotation

GitHub Actions / test

w3p.PrefixBlockNumber undefined (type map[uint64]string has no field or method PrefixBlockNumber)
c.Assert(ok, qt.Equals, true)
c.Assert(prefix, qt.Equals, "gor:123456")
})
t.Run("PrefixSymbol", func(t *testing.T) {
_, ok := w3p.PrefixSymbol(DefaultWeb3Provider.ChainID+1, "UNKNOWN")
c.Assert(ok, qt.IsFalse)
prefix, ok := w3p.PrefixSymbol(DefaultWeb3Provider.ChainID, "MON")
c.Assert(ok, qt.Equals, true)
c.Assert(prefix, qt.Equals, "gor:MON")
})
}
7 changes: 4 additions & 3 deletions state/web3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func Test_transferLogs(t *testing.T) {

logs, err := w.transferLogs(MonkeysCreationBlock, MonkeysCreationBlock+500)
c.Assert(err, qt.IsNil)
c.Assert(logs, qt.HasLen, 10)
c.Assert(logs, qt.HasLen, 12)
}

func Test_calcPartialBalances(t *testing.T) {
Expand All @@ -275,7 +275,7 @@ func Test_calcPartialBalances(t *testing.T) {
for addr, balance := range MonkeysHolders {
res, ok := hc[addr]
c.Assert(ok, qt.IsTrue)
c.Assert(res.String(), qt.Equals, balance.String())
c.Assert(res.String(), qt.Equals, balance.String(), qt.Commentf(addr.String()))
}
}

Expand All @@ -289,12 +289,13 @@ func Test_commitTokenHolders(t *testing.T) {

hc := HoldersCandidates(MonkeysHolders)
th := new(TokenHolders).Init(MonkeysAddress, CONTRACT_TYPE_ERC20, MonkeysCreationBlock, 5)
c.Assert(w.commitTokenHolders(th, hc, MonkeysCreationBlock+1000), qt.IsNil)
c.Assert(w.commitTokenHolders(th, hc, MonkeysCreationBlock+500), qt.IsNil)

c.Assert(th.LastBlock(), qt.Equals, MonkeysCreationBlock)
for addr, balance := range hc {
c.Assert(th.Exists(addr), qt.IsTrue)
val, ok := th.holders.Load(addr)
c.Logf("addr: %s, balance: %d, val: %d", addr.String(), balance, val.(*big.Int))
c.Assert(ok, qt.IsTrue)
c.Assert(val.(*big.Int).String(), qt.Equals, balance.String())
}
Expand Down

0 comments on commit 72d089c

Please sign in to comment.