Repository: coinbase/rosetta-cli
Pull request #290 (2022-03-24 14:29:34)

ROSE-231: Fix 'insufficient fund' error for UTXO chain when required_…
…coins is true

Fixes # .
https://jira.coinbase-corp.com/browse/ROSE-231

### Motivation
Fix 'insufficient fund' error for UTXO chain when required_coins is true

### Solution
See PR and https://github.com/coinbase/rosetta-sdk-go/pull/392 



Patch:
diff --git a/go.mod b/go.mod
index f45be1f..b20729c 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/coinbase/rosetta-cli
 go 1.16
 
 require (
-	github.com/coinbase/rosetta-sdk-go v0.7.4
+	github.com/coinbase/rosetta-sdk-go v0.7.6
 	github.com/fatih/color v1.13.0
 	github.com/olekukonko/tablewriter v0.0.5
 	github.com/pkg/errors v0.9.1
diff --git a/go.sum b/go.sum
index 5a58498..a6a7013 100644
--- a/go.sum
+++ b/go.sum
@@ -161,8 +161,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH
 github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
 github.com/coinbase/kryptology v1.8.0 h1:Aoq4gdTsJhSU3lNWsD5BWmFSz2pE0GlmrljaOxepdYY=
 github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI=
-github.com/coinbase/rosetta-sdk-go v0.7.4 h1:O1Usxxa1Bg2qiOGcbWZHXtjvOAeTUjk/gkVxYLaPtiw=
-github.com/coinbase/rosetta-sdk-go v0.7.4/go.mod h1:lt2lJX/HQ2stryuKkukCWMcX3T5fBU62UrdhuwsnVYg=
+github.com/coinbase/rosetta-sdk-go v0.7.6 h1:y3/Lxu9ojIsUKnhNc5UaZF/i0byfuNDWXLYMSKG+IBs=
+github.com/coinbase/rosetta-sdk-go v0.7.6/go.mod h1:lt2lJX/HQ2stryuKkukCWMcX3T5fBU62UrdhuwsnVYg=
 github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ=
 github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
 github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q=


Test patch:
diff --git a/pkg/tester/construction.go b/pkg/tester/construction.go
index 653b357..53ff7e8 100644
--- a/pkg/tester/construction.go
+++ b/pkg/tester/construction.go
@@ -205,6 +205,7 @@ func InitializeConstruction(
 
 	// Load prefunded accounts
 	var accountBalanceRequests []*utils.AccountBalanceRequest
+	var acctCoinsReqs []*utils.AccountCoinsRequest
 	for _, prefundedAcc := range config.Construction.PrefundedAccounts {
 		accountBalance := &utils.AccountBalanceRequest{
 			Account:  prefundedAcc.AccountIdentifier,
@@ -212,7 +213,15 @@ func InitializeConstruction(
 			Currency: prefundedAcc.Currency,
 		}
 
+		acctCoinsReq := &utils.AccountCoinsRequest{
+			Account:        prefundedAcc.AccountIdentifier,
+			Network:        network,
+			Currencies:     []*types.Currency{prefundedAcc.Currency},
+			IncludeMempool: false,
+		}
+
 		accountBalanceRequests = append(accountBalanceRequests, accountBalance)
+		acctCoinsReqs = append(acctCoinsReqs, acctCoinsReq)
 	}
 
 	accBalances, err := utils.GetAccountBalances(ctx, onlineFetcher, accountBalanceRequests)
@@ -225,11 +234,30 @@ func InitializeConstruction(
 		return nil, fmt.Errorf("%w: unable to set balances", err)
 	}
 
-	err = coinStorage.SetCoinsImported(ctx, accBalances)
+	// -------------------------------------------------------------------------
+	// ------------ Get account coins and add them in coins storage ------------
+	// -------------------------------------------------------------------------
+
+	acctCoins, errAccCoins := utils.GetAccountCoins(ctx, onlineFetcher, acctCoinsReqs)
+	if errAccCoins != nil {
+		return nil, fmt.Errorf("%w: unable to get account coins", errAccCoins)
+	}
+
+	// Extract accounts from account coins requests
+	var accts []*types.AccountIdentifier
+	for _, req := range acctCoinsReqs {
+		accts = append(accts, req.Account)
+	}
+
+	err = coinStorage.SetCoinsImported(ctx, accts, acctCoins)
 	if err != nil {
 		return nil, fmt.Errorf("%w: unable to set coin balances", err)
 	}
 
+	// --------------------------------------------------------------------------
+	// ---------------------- End of adding account coins -----------------------
+	// --------------------------------------------------------------------------
+
 	jobStorage := modules.NewJobStorage(localStore)
 	coordinatorHelper := processor.NewCoordinatorHelper(
 		offlineFetcher,