Skip to content

Commit

Permalink
Added more details when a contract push fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanHabic committed Feb 10, 2019
1 parent af2ceba commit 9f887d6
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
41 changes: 41 additions & 0 deletions commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ func uploadContracts(rest *rest.Rest) error {

contracts, err := getTruffleContracts(truffleConfig.AbsoluteBuildDirectoryPath())

if len(contracts) == 0 {
return userError.NewUserError(
fmt.Errorf("no contracts found in build dir: %s", truffleConfig.AbsoluteBuildDirectoryPath()),
aurora.Sprintf("No contracts detected in build directory: %s. This can happen when no contracts have been migrated yet.",
aurora.Bold(aurora.Green(truffleConfig.AbsoluteBuildDirectoryPath())),
),
)
}

logrus.Info("We have detected the following Smart Contracts:")
for _, contract := range contracts {
logrus.Info(fmt.Sprintf("• %s", contract.Name))
Expand Down Expand Up @@ -108,6 +117,38 @@ func uploadContracts(rest *rest.Rest) error {
)
}

if len(response.Contracts) != len(contracts) {
var nonPushedContracts []string

for _, contract := range contracts {
for networkId, network := range contract.Networks {
var found bool
for _, pushedContract := range response.Contracts {
if pushedContract.DeploymentInformation.Address == network.Address && pushedContract.DeploymentInformation.NetworkID == networkId {
found = true
break
}
}
if !found {
nonPushedContracts = append(nonPushedContracts, aurora.Sprintf(
"• %s on network %s with address %s",
aurora.Bold(aurora.Red(contract.Name)),
aurora.Bold(aurora.Red(networkId)),
aurora.Bold(aurora.Red(network.Address)),
))
}
}
}

return userError.NewUserError(
fmt.Errorf("unexpected number of pushed contracts. Got: %d expected: %d", len(response.Contracts), len(contracts)),
fmt.Sprintf("Some of the contracts haven't been pushed. This can happen when the contract isn't deployed to a supported network or some other error might have occurred. "+
"Below is the list with all the contracts that weren't pushed successfully:\n%s",
strings.Join(nonPushedContracts, "\n"),
),
)
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions rest/payloads/contractPayloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ type UploadContractsRequest struct {
}

type UploadContractsResponse struct {
Contracts []truffle.Contract `json:"contracts"`
Error *ApiError `json:"error"`
Contracts []truffle.ApiContract `json:"contracts"`
Error *ApiError `json:"error"`
}
27 changes: 27 additions & 0 deletions truffle/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ type ContractAst struct {
Src string `json:"src"`
}

type ApiContract struct {
ID string `json:"id"`

AccountID string `json:"account_id"`
ProjectID string `json:"project_id"`

NetworkID string `json:"network_id"`
Public bool `json:"public"`

Address string `json:"address"`

Name string `json:"contract_name"`

Abi string `json:"abi"`
Bytecode string `json:"bytecode"`
Source string `json:"source"`
SourceMap string `json:"source_map"`
DeploymentInformation *ApiDeploymentInformation `json:"deployment_information"`

CreatedAt time.Time `json:"created_at"`
}

type ApiDeploymentInformation struct {
NetworkID string `json:"network_id"`
Address string `json:"address"`
}

func NewContract(truffleContract Contract) (*stacktrace.Contract, error) {
abiString, err := json.Marshal(truffleContract.Abi)
if err != nil {
Expand Down

0 comments on commit 9f887d6

Please sign in to comment.