Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integrate lisk #63

Merged
merged 15 commits into from
Jan 4, 2023
Merged

Feature/integrate lisk #63

merged 15 commits into from
Jan 4, 2023

Conversation

foxy7595
Copy link
Contributor

No description provided.

chains/lisk/proto/block.proto Outdated Show resolved Hide resolved
chains/lisk/proto/block_asset.proto Outdated Show resolved Hide resolved
chains/lisk/proto/transaction.proto Outdated Show resolved Hide resolved
chains/lisk/proto/transaction_asset.proto Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
@foxy7595 foxy7595 force-pushed the feature/integrate-lisk branch 2 times, most recently from 50fa2fa to e7e397e Compare December 29, 2022 14:37
chains/lisk/block_fetcher.go Outdated Show resolved Hide resolved
chains/lisk/block_fetcher.go Outdated Show resolved Hide resolved
chains/lisk/block_fetcher.go Outdated Show resolved Hide resolved
chains/lisk/block_fetcher.go Outdated Show resolved Hide resolved
chains/lisk/client.go Outdated Show resolved Hide resolved
chains/lisk/client.go Outdated Show resolved Hide resolved
chains/lisk/client.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
chains/lisk/watcher.go Outdated Show resolved Hide resolved
core/processor.go Outdated Show resolved Hide resolved
core/processor.go Outdated Show resolved Hide resolved
@foxy7595 foxy7595 force-pushed the feature/integrate-lisk branch 2 times, most recently from 11bad92 to 98341b8 Compare December 29, 2022 17:16
}

var responseObject types.ResponseWrapper
json.Unmarshal(responseData, &responseObject)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.Unmarshal returns error. Make sure you catch that error here.

latestBlock := blocks[0]
latestBlockJson, _ := json.Marshal(latestBlock)
var block types.Block
if err := json.Unmarshal(latestBlockJson, &block); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do

block, ok := latestBlock.(*types.Block)

return nil, err
}
var block types.Block
if err := json.Unmarshal(latestBlockJson, &block); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block, ok := latestBlock.(*types.Block)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im using a map so we can't convert from map to interface
When I apply your code , I got this error invalid operation: latestBlock (variable of type map[string]interface{}) is not an interface

}
var transactions []types.Transaction
if err := json.Unmarshal(transactionsJson, &transactions); err != nil {
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated err checking

)

func testWatcher() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed

return ret
}
func (w *Watcher) acceptTx(tx types.Transaction) bool {
if tx.Asset.Recipient.Address != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to do nil checking here for tx.Asset and tx.Asset.Recipient or the app will crash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed.

@@ -0,0 +1,43 @@
package main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am moving away from creating a test folder for integration test.

Can you create a watcher_integration_test.go and put this test into that file? The test should have prefix TestIntegration_...

After you are done with the test, add test.Skip() so that the CI system will skip the test

@visopsys
Copy link
Contributor

visopsys commented Jan 1, 2023

You need to write test for the watcher. The test should cover at least 2 basic cases: The watcher should return a list of txs on a new block with interested txs and does not return when there is no tx going through watched address (though there are still txs in the block).

You can use in-memory db using InMemory flag to true. No need to mock the db.

ethtypes "github.com/ethereum/go-ethereum/core/types"
)

type MockEthClient struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you mock this for lisk?

return 0, err
}
blocks := responseObject.Data
latestBlock := blocks[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check length of blocks before doing this.

)
txFormatted := ctypes.Tx{
Hash: tx.Id,
Serialized: []byte(tx.Signatures[0]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check signatures length here

log.Info(w.cfg.Chain, " Block length = ", block.NumberOfTransactions)
txArr := make([]*ctypes.Tx, 0)
for _, tx := range block.Transactions {
if strings.EqualFold(tx.Sender.Address, w.vault) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong checking. We want to check the recipient of the asset, not the sender.

@visopsys visopsys merged commit cec872a into master Jan 4, 2023
@visopsys visopsys deleted the feature/integrate-lisk branch January 4, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants