diff --git a/cosmos/cosmos_chain.go b/cosmos/cosmos_chain.go index c2a8d0a..4e0b619 100644 --- a/cosmos/cosmos_chain.go +++ b/cosmos/cosmos_chain.go @@ -391,13 +391,13 @@ func (c *CosmosChain) ParamChangeProposal(ctx context.Context, keyName string, p } // SubmitFraudProposal submit a fraud proposal. -func (c *CosmosChain) SubmitFraudProposal(ctx context.Context, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit string) error { - _, err := c.getFullNode().SubmitFraudProposal(ctx, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit) +func (c *CosmosChain) SubmitFraudProposal(ctx context.Context, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit string) (tx TxProposal, _ error) { + txHash, err := c.getFullNode().SubmitFraudProposal(ctx, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit) if err != nil { - return fmt.Errorf("failed to submit fraud proposal: %w", err) + return tx, fmt.Errorf("failed to submit fraud proposal: %w", err) } - return nil + return c.txProposal(txHash) } // QueryParam returns the param state of a given key. diff --git a/cosmos/hub/dym_hub/dym_hub.go b/cosmos/hub/dym_hub/dym_hub.go index da2478f..e077ebb 100644 --- a/cosmos/hub/dym_hub/dym_hub.go +++ b/cosmos/hub/dym_hub/dym_hub.go @@ -421,7 +421,7 @@ func (c *DymHub) QueryRollappState(ctx context.Context, var command []string command = append(command, "rollapp", "state", rollappName) - + if onlyFinalized { command = append(command, "--finalized") } @@ -444,7 +444,7 @@ func (c *DymHub) QueryLatestStateIndex(ctx context.Context, ) (*dymension.QueryGetLatestStateIndexResponse, error) { var command []string command = append(command, "rollapp", "latest-state-index", rollappName) - + if onlyFinalized { command = append(command, "--finalized") } @@ -550,3 +550,28 @@ func (c *DymHub) WaitUntilRollappHeightIsFinalized(ctx context.Context, rollappC } } } + +func (c *DymHub) AssertFinalization(ctx context.Context, rollappName string, minIndex, timeoutSecs uint64) (bool, error) { + + startTime := time.Now() + timeout := time.Duration(timeoutSecs) * time.Second + + for { + select { + case <-time.After(timeout): + return false, fmt.Errorf("timeout reached without rollap state finalization index reach: %d", minIndex) + default: + latestFinalizedIndex, err := c.FinalizedRollappStateIndex(ctx, rollappName) + if err != nil { + if time.Since(startTime) < timeout { + time.Sleep(2 * time.Second) // 2sec interval + continue + } + } + + if latestFinalizedIndex >= minIndex { + return true, nil + } + } + } +}