Repository: vegaprotocol/vegawallet
Pull request #559 (2022-05-06 07:44:22)

feat: remove dv system-tests
Related PRs:

- https://github.com/vegaprotocol/vegawallet/pull/559
- https://github.com/vegaprotocol/vega/pull/5336
- https://github.com/vegaprotocol/system-tests/pull/765
- https://github.com/vegaprotocol/data-node/pull/593

github-actions[bot]: Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>
github-actions[bot]: Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>
github-actions[bot]: Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>
github-actions[bot]: Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2193ec3..ddfb3d7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
 - [](https://github.com/vegaprotocol/vegawallet/pull/) -
 
 ### 🛠  Improvements
+- [555](https://github.com/vegaprotocol/vegawallet/issues/555) - Now using full transaction structures for event emit
 - [551](https://github.com/vegaprotocol/vegawallet/pull/551) - Enable system-tests with Vegacapsule
 
 ### 🔥 Removal
diff --git a/Jenkinsfile b/Jenkinsfile
index ad6804d..e1c9fc6 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -162,21 +162,6 @@ pipeline {
                         '''
                     }
                 }
-                stage('System Tests') {
-                    steps {
-                        script {
-                            systemTests ignoreFailure: !isPRBuild(),
-                                vegaCore: params.VEGA_CORE_BRANCH,
-                                dataNode: params.DATA_NODE_BRANCH,
-                                vegawallet: commitHash,
-                                ethereumEventForwarder: params.ETHEREUM_EVENT_FORWARDER_BRANCH,
-                                devopsInfra: params.DEVOPS_INFRA_BRANCH,
-                                vegatools: params.VEGATOOLS_BRANCH,
-                                systemTests: params.SYSTEM_TESTS_BRANCH,
-                                protos: params.PROTOS_BRANCH
-                        }
-                    }
-                }
                 stage('LNL System Tests') {
                     steps {
                         script {
diff --git a/cmd/service_run.go b/cmd/service_run.go
index 4de954e..a382c3b 100644
--- a/cmd/service_run.go
+++ b/cmd/service_run.go
@@ -399,12 +399,13 @@ func waitSig(ctx context.Context, cfunc func(), log *zap.Logger, pendingSigReque
 
 				sentTx := <-sentTxs
 				if sentTx.Error != nil {
+					log.Error("transaction failed", zap.Any("transaction", txStr))
 					p.BangMark().DangerText("Transaction failed! ").NextLine()
 					p.BangMark().DangerText("Error: ").DangerText(sentTx.Error.Error()).NextLine()
 					p.BangMark().DangerText("Details: ").DangerText(strings.Join(sentTx.ErrorDetails, " ,")).NextSection()
 				} else {
-					p.CheckMark().SuccessText("Transaction sent! ").NextLine()
-					p.CheckMark().Text("Transaction hash: ").SuccessText(sentTx.TxHash).NextSection()
+					log.Info("transaction sent", zap.Any("hash", sentTx.TxHash))
+					p.CheckMark().Text("Transaction with hash ").SuccessText(sentTx.TxHash).Text(" sent!").NextSection()
 				}
 			} else {
 				log.Info("user rejected the signing of the transaction", zap.Any("transaction", txStr))
diff --git a/service/mocks/policies_mock.go b/service/mocks/policies_mock.go
index ccff0b2..6ed0daa 100644
--- a/service/mocks/policies_mock.go
+++ b/service/mocks/policies_mock.go
@@ -1,6 +1,8 @@
 package mocks
 
 import (
+	"time"
+
 	v1 "code.vegaprotocol.io/protos/vega/wallet/v1"
 	"code.vegaprotocol.io/vegawallet/service"
 )
@@ -21,7 +23,7 @@ func NewMockConsentPolicy(pending chan service.ConsentRequest, sentTxs chan serv
 	}
 }
 
-func (p *MockConsentPolicy) Ask(tx *v1.SubmitTransactionRequest) (bool, error) {
+func (p *MockConsentPolicy) Ask(tx *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error) {
 	if tx.PubKey == "toBeDeclined" {
 		return false, nil
 	}
diff --git a/service/policies.go b/service/policies.go
index a4d8d2b..b9306df 100644
--- a/service/policies.go
+++ b/service/policies.go
@@ -1,8 +1,6 @@
 package service
 
 import (
-	"crypto/sha256"
-	"fmt"
 	"time"
 
 	commandspb "code.vegaprotocol.io/protos/vega/commands/v1"
@@ -28,22 +26,17 @@ func (r *ConsentRequest) String() (string, error) {
 	return marshalledRequest, err
 }
 
-func (r *ConsentRequest) GetTxID() string {
-	h := sha256.New()
-	h.Write([]byte(fmt.Sprintf("%s%v%t", r.Tx.PubKey, r.Tx.Command, r.Tx.Propagate)))
-
-	return fmt.Sprintf("%x", h.Sum(nil))
-}
-
 type SentTransaction struct {
 	TxHash       string
+	TxID         string
+	ReceivedAt   time.Time
 	Tx           *commandspb.Transaction
 	Error        error
 	ErrorDetails []string
 }
 
 type Policy interface {
-	Ask(tx *v1.SubmitTransactionRequest) (bool, error)
+	Ask(tx *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error)
 	Report(tx SentTransaction)
 	NeedsInteractiveOutput() bool
 }
@@ -54,7 +47,7 @@ func NewAutomaticConsentPolicy() Policy {
 	return &AutomaticConsentPolicy{}
 }
 
-func (p *AutomaticConsentPolicy) Ask(_ *v1.SubmitTransactionRequest) (bool, error) {
+func (p *AutomaticConsentPolicy) Ask(_ *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error) {
 	return true, nil
 }
 
@@ -78,10 +71,10 @@ func NewExplicitConsentPolicy(pending chan ConsentRequest, sentTxs chan SentTran
 	}
 }
 
-func (p *ExplicitConsentPolicy) Ask(tx *v1.SubmitTransactionRequest) (bool, error) {
+func (p *ExplicitConsentPolicy) Ask(tx *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error) {
 	confirmations := make(chan ConsentConfirmation)
-	consentReq := ConsentRequest{Tx: tx, Confirmations: confirmations, ReceivedAt: time.Now()}
-	consentReq.TxID = consentReq.GetTxID()
+	consentReq := ConsentRequest{Tx: tx, Confirmations: confirmations, ReceivedAt: receivedAt}
+	consentReq.TxID = txID
 	p.pendingEvents <- consentReq
 
 	c := <-confirmations
diff --git a/service/service.go b/service/service.go
index 4ee1f46..ac52344 100644
--- a/service/service.go
+++ b/service/service.go
@@ -9,6 +9,9 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"time"
+
+	vgrand "code.vegaprotocol.io/shared/libs/rand"
 
 	"code.vegaprotocol.io/protos/commands"
 	typespb "code.vegaprotocol.io/protos/vega"
@@ -46,6 +49,8 @@ type CreateWalletRequest struct {
 	Passphrase string `json:"passphrase"`
 }
 
+const TXIDLENGTH = 20
+
 func ParseCreateWalletRequest(r *http.Request) (*CreateWalletRequest, commands.Errors) {
 	errs := commands.NewErrors()
 
@@ -736,7 +741,9 @@ func (s *Service) signTx(token string, w http.ResponseWriter, r *http.Request, _
 		return
 	}
 
-	approved, err := s.policy.Ask(req)
+	txID := vgrand.RandomStr(TXIDLENGTH)
+	receivedAt := time.Now()
+	approved, err := s.policy.Ask(req, txID, receivedAt)
 	if err != nil {
 		s.log.Panic("failed getting transaction sign request answer", zap.Error(err))
 	}
@@ -785,14 +792,18 @@ func (s *Service) signTx(token string, w http.ResponseWriter, r *http.Request, _
 			}
 			s.policy.Report(SentTransaction{
 				Tx:           tx,
+				ReceivedAt:   receivedAt,
+				TxID:         txID,
 				Error:        err,
 				ErrorDetails: details,
 			})
 			s.writeError(w, newErrorWithDetails(err.Error(), details), http.StatusInternalServerError)
 		} else {
 			s.policy.Report(SentTransaction{
-				Tx:    tx,
-				Error: err,
+				Tx:         tx,
+				ReceivedAt: receivedAt,
+				TxID:       txID,
+				Error:      err,
 			})
 			s.writeInternalError(w, err)
 		}
@@ -800,16 +811,22 @@ func (s *Service) signTx(token string, w http.ResponseWriter, r *http.Request, _
 	}
 
 	s.policy.Report(SentTransaction{
-		TxHash: txHash,
-		Tx:     tx,
+		TxHash:     txHash,
+		ReceivedAt: receivedAt,
+		TxID:       txID,
+		Tx:         tx,
 	})
 
 	s.writeSuccess(w, struct {
-		TxHash string                  `json:"txHash"`
-		Tx     *commandspb.Transaction `json:"tx"`
+		TxHash     string                  `json:"txHash"`
+		ReceivedAt time.Time               `json:"receivedAt"`
+		TxID       string                  `json:"txId"`
+		Tx         *commandspb.Transaction `json:"tx"`
 	}{
-		TxHash: txHash,
-		Tx:     tx,
+		TxHash:     txHash,
+		ReceivedAt: receivedAt,
+		TxID:       txID,
+		Tx:         tx,
 	})
 }
 


Test patch:
diff --git a/service/service_test.go b/service/service_test.go
index 2f16bac..f0e2224 100644
--- a/service/service_test.go
+++ b/service/service_test.go
@@ -735,9 +735,22 @@ func testAskingConsentPolicySucceeds(t *testing.T) {
 		req.Confirmations <- d
 	}()
 
-	answer, err := p.Ask(txn)
+	nowTime := time.Now()
+	answer, err := p.Ask(txn, "testTx", nowTime)
 	require.Nil(t, err)
 	require.False(t, answer)
+
+	p.Report(service.SentTransaction{
+		TxHash:     "txHash",
+		ReceivedAt: nowTime,
+		TxID:       "testTx",
+		Tx:         &commandspb.Transaction{},
+	})
+
+	sent := <-sentTxs
+	require.Equal(t, "txHash", sent.TxHash)
+	require.Equal(t, "testTx", sent.TxID)
+	require.Equal(t, nowTime, sent.ReceivedAt)
 }
 
 func testDeclineSigningTransactionManuallySucceeds(t *testing.T) {