From 72d089c09bacd65dfeb37564bc1ec4cbb940bcbd Mon Sep 17 00:00:00 2001 From: Lucas Menendez Date: Tue, 3 Oct 2023 22:04:44 +0200 Subject: [PATCH] new tests for multiple web3 providers stuff and other tests updated with the test holders balances changes of test token --- census/census_test.go | 7 ++++-- service/helper_test.go | 6 ++++-- state/helper_test.go | 16 +++++++++----- state/providers_test.go | 47 +++++++++++++++++++++++++++++++++++++++++ state/web3_test.go | 7 +++--- 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 state/providers_test.go diff --git a/census/census_test.go b/census/census_test.go index b0577e89..91edb579 100644 --- a/census/census_test.go +++ b/census/census_test.go @@ -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) { diff --git a/service/helper_test.go b/service/helper_test.go index 9ac5aea8..bc01c299 100644 --- a/service/helper_test.go +++ b/service/helper_test.go @@ -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), } ) diff --git a/state/helper_test.go b/state/helper_test.go index fd7780a8..d4433b85 100644 --- a/state/helper_test.go +++ b/state/helper_test.go @@ -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{ + 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 } diff --git a/state/providers_test.go b/state/providers_test.go new file mode 100644 index 00000000..b1bc9d7b --- /dev/null +++ b/state/providers_test.go @@ -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) + c.Assert(w3p[DefaultWeb3Provider.ChainID].ShortName, qt.Equals, DefaultWeb3Provider.ShortName) + c.Assert(w3p[DefaultWeb3Provider.ChainID].Name, qt.Equals, DefaultWeb3Provider.Name) + + t.Run("URIByChainID", func(t *testing.T) { + _, ok := w3p.URIByChainID(DefaultWeb3Provider.ChainID + 1) + c.Assert(ok, qt.IsFalse) + uri, ok := w3p.URIByChainID(DefaultWeb3Provider.ChainID) + c.Assert(ok, qt.Equals, true) + c.Assert(uri, qt.Equals, DefaultWeb3Provider.URI) + }) + t.Run("ChainIDByShortName", func(t *testing.T) { + _, ok := w3p.ChainIDByShortName("UNKNOWN") + c.Assert(ok, qt.IsFalse) + chainID, ok := w3p.ChainIDByShortName(DefaultWeb3Provider.ShortName) + 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) + c.Assert(ok, qt.IsFalse) + prefix, ok := w3p.PrefixBlockNumber(DefaultWeb3Provider.ChainID, 123456) + 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") + }) +} diff --git a/state/web3_test.go b/state/web3_test.go index 2fd40625..ce9e9b36 100644 --- a/state/web3_test.go +++ b/state/web3_test.go @@ -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) { @@ -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())) } } @@ -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()) }