-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/vitwit/avail-da-module into…
… 18_refactor_code
- Loading branch information
Showing
16 changed files
with
821 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,78 @@ | ||
package keeper_test | ||
|
||
// import ( | ||
// abci "github.com/cometbft/cometbft/abci/types" | ||
// store "github.com/vitwit/avail-da-module/keeper" | ||
// ) | ||
import ( | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
store "github.com/vitwit/avail-da-module/keeper" | ||
) | ||
|
||
// func (s *TestSuite) TestExtendVoteHandler() { | ||
func (s *TestSuite) TestExtendVoteHandler() { | ||
testCases := []struct { | ||
name string | ||
startHeight uint64 | ||
endHeight uint64 | ||
availHeight uint64 | ||
blobStatus uint32 | ||
currentHeight int64 | ||
voteEndHeight uint64 | ||
isLastVoting bool | ||
expectErr bool | ||
}{ | ||
{ | ||
"blob status is not in voting state", | ||
uint64(1), | ||
uint64(20), | ||
uint64(30), | ||
uint32(3), | ||
int64(22), | ||
uint64(20), | ||
false, | ||
false, | ||
}, | ||
{ | ||
"blob status is in voting state", | ||
uint64(1), | ||
uint64(20), | ||
uint64(30), | ||
uint32(2), | ||
int64(30), | ||
uint64(31), | ||
true, | ||
false, | ||
}, | ||
} | ||
|
||
// testCases := []struct { | ||
// name string | ||
// startHeight uint64 | ||
// endHeight uint64 | ||
// availHeight uint64 | ||
// blobStatus uint32 | ||
// currentHeight int64 | ||
// voteEndHeight uint64 | ||
// expectErr bool | ||
// }{ | ||
// { | ||
// "blob status is not in voting state", | ||
// uint64(1), | ||
// uint64(20), | ||
// uint64(30), | ||
// uint32(1), | ||
// int64(22), | ||
// uint64(20), | ||
// false, | ||
// }, | ||
// { | ||
// "blob status is in voting state", | ||
// uint64(1), | ||
// uint64(20), | ||
// uint64(30), | ||
// uint32(2), | ||
// int64(30), | ||
// uint64(31), | ||
// false, | ||
// }, | ||
// } | ||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
s.ctx = s.ctx.WithBlockHeight(tc.currentHeight) | ||
|
||
// for _, tc := range testCases { | ||
// s.Run(tc.name, func() { | ||
// s.ctx = s.ctx.WithBlockHeight(tc.currentHeight) | ||
err := store.UpdateStartHeight(s.ctx, s.store, tc.startHeight) | ||
s.Require().NoError(err) | ||
|
||
// err := store.UpdateStartHeight(s.ctx, s.store, tc.startHeight) | ||
// s.Require().NoError(err) | ||
err = store.UpdateEndHeight(s.ctx, s.store, tc.endHeight) | ||
s.Require().NoError(err) | ||
|
||
// err = store.UpdateEndHeight(s.ctx, s.store, tc.endHeight) | ||
// s.Require().NoError(err) | ||
err = store.UpdateAvailHeight(s.ctx, s.store, tc.availHeight) | ||
s.Require().NoError(err) | ||
|
||
// err = store.UpdateAvailHeight(s.ctx, s.store, tc.availHeight) | ||
// s.Require().NoError(err) | ||
err = store.UpdateBlobStatus(s.ctx, s.store, tc.blobStatus) | ||
s.Require().NoError(err) | ||
|
||
// err = store.UpdateBlobStatus(s.ctx, s.store, tc.blobStatus) | ||
// s.Require().NoError(err) | ||
err = store.UpdateVotingEndHeight(s.ctx, s.store, tc.voteEndHeight, tc.isLastVoting) | ||
s.Require().NoError(err) | ||
|
||
// err = store.UpdateVotingEndHeight(s.ctx, s.store, tc.voteEndHeight) | ||
// s.Require().NoError(err) | ||
extendVoteHandler := s.voteExtensionHandler.ExtendVoteHandler() | ||
|
||
// extendVoteHandler := s.voteExtensionHandler.ExtendVoteHandler() | ||
req := &abci.RequestExtendVote{ | ||
ProposerAddress: s.addrs[1], | ||
} | ||
|
||
// req := &abci.RequestExtendVote{ | ||
// ProposerAddress: s.addrs[1], | ||
// } | ||
|
||
// res, err := extendVoteHandler(s.ctx, req) | ||
// if tc.expectErr { | ||
// s.Require().Error(err) | ||
// } else { | ||
// s.Require().NoError(err) | ||
// s.Require().NotNil(res) | ||
// } | ||
// }) | ||
// } | ||
|
||
// } | ||
res, err := extendVoteHandler(s.ctx, req) | ||
if tc.expectErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().NotNil(res) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package avail_test | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
avail "github.com/vitwit/avail-da-module/relayer/avail" | ||
httpClient "github.com/vitwit/avail-da-module/relayer/http" | ||
) | ||
|
||
func newMockLightClient(serverURL string) *avail.LightClient { | ||
httpClient := httpClient.NewHandler() | ||
return avail.NewLightClient(serverURL, httpClient) | ||
} | ||
|
||
// Test IsDataAvailable | ||
func TestLightClient_IsDataAvailable(t *testing.T) { | ||
expectedBlockHeight := 100 | ||
expectedBase64Data := base64.StdEncoding.EncodeToString([]byte("cosmos-block-data")) | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
block := avail.Block{ | ||
Block: 100, | ||
Extrinsics: []avail.Extrinsics{ | ||
{Data: expectedBase64Data}, | ||
}, | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(block) | ||
})) | ||
defer mockServer.Close() | ||
|
||
lightClient := newMockLightClient(mockServer.URL) | ||
|
||
isAvailable, err := lightClient.IsDataAvailable([]byte("cosmos-block-data"), expectedBlockHeight) | ||
assert.NoError(t, err, "expected no error") | ||
assert.True(t, isAvailable, "expected data to be available") | ||
} | ||
|
||
func TestLightClient_GetBlock(t *testing.T) { | ||
expectedBlockHeight := 100 | ||
expectedExtrinsics := []avail.Extrinsics{ | ||
{Data: base64.StdEncoding.EncodeToString([]byte("cosmos-block-data"))}, | ||
} | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
block := avail.Block{ | ||
Block: int64(expectedBlockHeight), | ||
Extrinsics: expectedExtrinsics, | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(block) | ||
})) | ||
defer mockServer.Close() | ||
|
||
lightClient := newMockLightClient(mockServer.URL) | ||
|
||
block, err := lightClient.GetBlock(expectedBlockHeight) | ||
assert.NoError(t, err, "expected no error") | ||
assert.Equal(t, expectedBlockHeight, int(block.Block), "expected block height to match") | ||
assert.Equal(t, expectedExtrinsics, block.Extrinsics, "expected extrinsics to match") | ||
} | ||
|
||
func TestLightClient_Submit(t *testing.T) { | ||
expectedBlockMetaData := avail.BlockMetaData{ | ||
BlockNumber: 100, | ||
BlockHash: "testhash", | ||
Hash: "datahash", | ||
Index: 1, | ||
} | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(expectedBlockMetaData) | ||
})) | ||
defer mockServer.Close() | ||
|
||
lightClient := newMockLightClient(mockServer.URL) | ||
|
||
blockMeta, err := lightClient.Submit([]byte("testdata")) | ||
assert.NoError(t, err, "expected no error") | ||
assert.Equal(t, expectedBlockMetaData, blockMeta, "expected block metadata to match") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.