-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add support for broadcasting arbitrary messages as test users #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple high-level notes:
- Move
Broadcast
interface into rootibctest
package cosmos_broadcaster.go
can be named justbroadcaster.go
since it is already in thecosmos
directory
I think the Broadcast interface is fine to focus on Cosmos, but others on the team have given Cosmos vs non-Cosmos more thought than I have, so it would be good to hear from someone else.
broadcast/broadcast.go
Outdated
@@ -0,0 +1,59 @@ | |||
package broadcast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the types here make more sense in the root ibctest
package.
broadcast/broadcast.go
Outdated
|
||
type FactoryOpt func(factory tx.Factory) tx.Factory | ||
|
||
type User interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After moving to ibctest
, this interface can be named BroadcastUser
to distinguish from the User
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are in the ibctest
package I believe we may just be able to accept an *ibctest.User
directly. However maybe it is no harm to keep the interface.
broadcast/broadcast.go
Outdated
|
||
// Tx uses the provided Broadcaster to broadcast all the provided messages which will be signed | ||
// by the User provided. The sdk.TxResponse and an error are returned. | ||
func Tx(ctx context.Context, broadcaster Broadcaster, broadcastingUser User, msgs ...sdk.Msg) (sdk.TxResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this function can be named BroadcastTx
.
chain/cosmos/cosmos_broadcaster.go
Outdated
// defaultClientContext returns a default client context configured with the user as the sender. | ||
func (b *Broadcaster) defaultClientContext(fromUser broadcast.User, sdkAdd sdk.AccAddress) client.Context { | ||
// initialize a clean buffer each time | ||
b.buf = &bytes.Buffer{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be b.buf.Reset()
.
internal/dockerutil/keyring.go
Outdated
splitName := strings.Split(name, "/") | ||
|
||
extractedFileName := splitName[len(splitName)-1] | ||
isDirectory := extractedFileName == "" | ||
if isDirectory { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use isDirectory := strings.HasSuffix(name, "/")
and extractedFileName := path.Base(name)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much cleaner, thanks for the suggestion!
@mark-rushakoff moving the code into the Some options are:
|
I ended up keeping the interfaces in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this came together nicely. Thanks for figuring out a workaround for the import cycle I inadvertently suggested last week. I left a few comments on some minor style points, and then I think this can be merged.
interchain_test.go
Outdated
require.Equal(t, uint32(0), resp.Code) | ||
require.NotEmpty(t, resp.Data) | ||
require.NotEmpty(t, resp.TxHash) | ||
require.NotEmpty(t, resp.Events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this test also have an assertion that the user on gaia1 has received transferAmount
?
internal/dockerutil/keyring.go
Outdated
return nil, err | ||
} | ||
|
||
if err := os.Mkdir(fmt.Sprintf("%s/keyring-test", localDirectory), os.ModePerm); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is working on a local filesystem, it should use filepath.Join(localDirectory, "keyring-test")
instead of fmt.Sprintf
with a literal /
.
internal/dockerutil/keyring.go
Outdated
continue | ||
} | ||
|
||
filePath := fmt.Sprintf("%s/keyring-test/%s", localDirectory, extractedFileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
here too.
chain/cosmos/broadcaster.go
Outdated
} | ||
|
||
// GetFactory returns an instance of tx.Factory that is configured with this Broadcaster's CosmosChain | ||
// and the provided user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't hurt to mention ConfigureFactoryOptions
in the godoc for this method.
chain/cosmos/broadcaster.go
Outdated
_, ok := b.keyrings[user] | ||
if !ok { | ||
localDir := b.t.TempDir() | ||
containerKeyringDir := fmt.Sprintf("%s/keyring-test", cn.HomeDir()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
chain/cosmos/broadcaster.go
Outdated
// GetTxResponseBytes returns the sdk.TxResponse bytes which returned from broadcast.Tx. | ||
func (b *Broadcaster) GetTxResponseBytes(ctx context.Context, user broadcast.User) ([]byte, error) { | ||
if b.buf == nil || b.buf.Len() == 0 { | ||
return nil, fmt.Errorf("empty buffer, transaction has not be executed yet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/be/been/
I've opened a separate PR to add support for the keyrings that we were discussing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
This PR adds support for the ability to Broadcast transactions on CosmosChains
closes #185
Checklist
Changes
Broadcaster
NewLocalKeyringFromDockerContainer
a mechanism to use the keychain of created test users.NewLocalKeyringFromDockerContainer
works as this would fail if the keyring was not there. )Notes