Repository: ovrclk/akash
Pull request #656 (2020-06-11 06:05:28)

bugfix: fix events
* `./events`: re-add listening to tx events
* `./x/deployment/types`: fix close deployment tx
* `./provider/cmd/run`: non-colorized logging
* `./testutil`: coin generator.

codecov[bot]: # [Codecov](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=h1) Report
> Merging [#656](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=desc) into [master](https://codecov.io/gh/ovrclk/akash/commit/1a56898332802e1d012225bbab913e3432e099b5&el=desc) will **increase** coverage by `1.09%`.
> The diff coverage is `20.83%`.

[![Impacted file tree graph](https://codecov.io/gh/ovrclk/akash/pull/656/graphs/tree.svg?width=650&height=150&src=pr&token=QXe3zmrbI2)](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #656      +/-   ##
==========================================
+ Coverage   25.57%   26.66%   +1.09%     
==========================================
  Files         145      147       +2     
  Lines        6858     6881      +23     
==========================================
+ Hits         1754     1835      +81     
+ Misses       4998     4916      -82     
- Partials      106      130      +24     
```


| [Impacted Files](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [events/publish.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-ZXZlbnRzL3B1Ymxpc2guZ28=) | `11.11% <0.00%> (+11.11%)` | :arrow_up: |
| [events/query.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-ZXZlbnRzL3F1ZXJ5Lmdv) | `0.00% <0.00%> (ø)` | |
| [provider/cluster/service.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-cHJvdmlkZXIvY2x1c3Rlci9zZXJ2aWNlLmdv) | `0.00% <0.00%> (ø)` | |
| [provider/cmd/logger.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-cHJvdmlkZXIvY21kL2xvZ2dlci5nbw==) | `0.00% <0.00%> (ø)` | |
| [provider/cmd/run.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-cHJvdmlkZXIvY21kL3J1bi5nbw==) | `0.00% <0.00%> (ø)` | |
| [x/deployment/types/event.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-eC9kZXBsb3ltZW50L3R5cGVzL2V2ZW50Lmdv) | `91.89% <60.00%> (+19.42%)` | :arrow_up: |
| [testutil/price.go](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree#diff-dGVzdHV0aWwvcHJpY2UuZ28=) | `100.00% <100.00%> (ø)` | |
| ... and [3 more](https://codecov.io/gh/ovrclk/akash/pull/656/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=footer). Last update [1a56898...4452763](https://codecov.io/gh/ovrclk/akash/pull/656?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/events/publish.go b/events/publish.go
index e02cb2a6..e154ce9b 100644
--- a/events/publish.go
+++ b/events/publish.go
@@ -23,9 +23,16 @@ func Publish(ctx context.Context, tmbus tmclient.EventsClient, name string, bus
 		queuesz = 100
 	)
 	var (
+		txname  = name + "-tx"
 		blkname = name + "-blk"
 	)
 
+	txch, err := tmbus.Subscribe(ctx, txname, txQuery().String(), queuesz)
+	if err != nil {
+		return err
+	}
+	defer tmbus.UnsubscribeAll(ctx, txname)
+
 	blkch, err := tmbus.Subscribe(ctx, blkname, blkQuery().String(), queuesz)
 	if err != nil {
 		return err
@@ -34,6 +41,10 @@ func Publish(ctx context.Context, tmbus tmclient.EventsClient, name string, bus
 
 	g, ctx := errgroup.WithContext(ctx)
 
+	g.Go(func() error {
+		return publishEvents(ctx, txch, bus)
+	})
+
 	g.Go(func() error {
 		return publishEvents(ctx, blkch, bus)
 	})
diff --git a/events/query.go b/events/query.go
index 52dca417..249b842e 100644
--- a/events/query.go
+++ b/events/query.go
@@ -8,6 +8,11 @@ import (
 	tmtypes "github.com/tendermint/tendermint/types"
 )
 
+func txQuery() pubsub.Query {
+	return tmquery.MustParse(
+		fmt.Sprintf("%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx))
+}
+
 func blkQuery() pubsub.Query {
 	return tmquery.MustParse(
 		fmt.Sprintf("%s='%s'", tmtypes.EventTypeKey, tmtypes.EventNewBlockHeader))
diff --git a/provider/cmd/run.go b/provider/cmd/run.go
index 30365e5a..5cc1e34d 100644
--- a/provider/cmd/run.go
+++ b/provider/cmd/run.go
@@ -9,6 +9,7 @@ import (
 	"github.com/cosmos/cosmos-sdk/codec"
 	"github.com/cosmos/cosmos-sdk/x/auth"
 	"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
+	"github.com/go-kit/kit/log/term"
 	"github.com/ovrclk/akash/client"
 	"github.com/ovrclk/akash/cmd/common"
 	"github.com/ovrclk/akash/events"
@@ -66,7 +67,7 @@ func doRunCmd(ctx context.Context, cdc *codec.Codec, cmd *cobra.Command, _ []str
 
 	gwaddr := viper.GetString(flagGatewayListenAddress)
 
-	log := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
+	log := openLogger()
 
 	// TODO: actually get the passphrase?
 	// passphrase, err := keys.GetPassphrase(fromName)
@@ -133,6 +134,13 @@ func doRunCmd(ctx context.Context, cdc *codec.Codec, cmd *cobra.Command, _ []str
 	return group.Wait()
 }
 
+func openLogger() log.Logger {
+	// logger with no color output - current debug colors are invisible for me.
+	return log.NewTMLoggerWithColorFn(log.NewSyncWriter(os.Stdout), func(_ ...interface{}) term.FgBgColor {
+		return term.FgBgColor{}
+	})
+}
+
 func createClusterClient(log log.Logger, cmd *cobra.Command, host string) (cluster.Client, error) {
 	if val, _ := cmd.Flags().GetBool(flagClusterK8s); !val {
 		// Condition that there is no Kubernetes API to work with.
diff --git a/x/deployment/types/event.go b/x/deployment/types/event.go
index f628c82c..4c8be706 100644
--- a/x/deployment/types/event.go
+++ b/x/deployment/types/event.go
@@ -134,6 +134,12 @@ func ParseEvent(ev sdkutil.Event) (interface{}, error) {
 			return nil, err
 		}
 		return EventDeploymentUpdate{ID: did}, nil
+	case evActionDeploymentClose:
+		did, err := ParseEVDeploymentID(ev.Attributes)
+		if err != nil {
+			return nil, err
+		}
+		return EventDeploymentClose{ID: did}, nil
 	default:
 		return nil, sdkutil.ErrUnknownAction
 	}


Test patch:
diff --git a/events/publish_test.go b/events/publish_test.go
new file mode 100644
index 00000000..742d6883
--- /dev/null
+++ b/events/publish_test.go
@@ -0,0 +1,42 @@
+package events
+
+import (
+	"testing"
+
+	sdk "github.com/cosmos/cosmos-sdk/types"
+	"github.com/ovrclk/akash/testutil"
+	dtypes "github.com/ovrclk/akash/x/deployment/types"
+	mtypes "github.com/ovrclk/akash/x/market/types"
+	"github.com/stretchr/testify/assert"
+)
+
+func Test_processEvent(t *testing.T) {
+	tests := []interface {
+		ToSDKEvent() sdk.Event
+	}{
+		// x/deployment events
+		dtypes.EventDeploymentCreate{ID: testutil.DeploymentID(t)},
+		dtypes.EventDeploymentUpdate{ID: testutil.DeploymentID(t)},
+		dtypes.EventDeploymentClose{ID: testutil.DeploymentID(t)},
+
+		// x/market events
+		mtypes.EventOrderCreated{ID: testutil.OrderID(t)},
+		mtypes.EventOrderClosed{ID: testutil.OrderID(t)},
+		mtypes.EventBidCreated{ID: testutil.BidID(t), Price: testutil.Coin(t)},
+		mtypes.EventBidClosed{ID: testutil.BidID(t), Price: testutil.Coin(t)},
+		mtypes.EventLeaseCreated{ID: testutil.LeaseID(t), Price: testutil.Coin(t)},
+		mtypes.EventLeaseClosed{ID: testutil.LeaseID(t), Price: testutil.Coin(t)},
+	}
+
+	for _, test := range tests {
+		sdkevs := sdk.Events{
+			test.ToSDKEvent(),
+		}.ToABCIEvents()
+
+		sdkev := sdkevs[0]
+
+		ev, ok := processEvent(sdkev)
+		assert.True(t, ok, test)
+		assert.Equal(t, test, ev, test)
+	}
+}
diff --git a/testutil/sdk.go b/testutil/sdk.go
new file mode 100644
index 00000000..3204e1c8
--- /dev/null
+++ b/testutil/sdk.go
@@ -0,0 +1,12 @@
+package testutil
+
+import (
+	"math/rand"
+	"testing"
+
+	sdk "github.com/cosmos/cosmos-sdk/types"
+)
+
+func Coin(_ testing.TB) sdk.Coin {
+	return sdk.NewCoin("testcoin", sdk.NewInt(rand.Int63()))
+}