Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Oct 8, 2024
1 parent e8cb281 commit 085899d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
op := operation.operation.Body.MustClaimClaimableBalanceOp()
balanceID, err := xdr.MarshalHex(op.BalanceId)
if err != nil {
panic(fmt.Errorf("Invalid balanceId in op: %d", operation.index))
return nil, fmt.Errorf("Invalid balanceId in op: %d", operation.index)
}
details["balance_id"] = balanceID
addAccountAndMuxedAccountDetails(details, *source, "claimant")
Expand Down Expand Up @@ -585,7 +585,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
op := operation.operation.Body.MustClawbackClaimableBalanceOp()
balanceID, err := xdr.MarshalHex(op.BalanceId)
if err != nil {
panic(fmt.Errorf("Invalid balanceId in op: %d", operation.index))
return nil, fmt.Errorf("Invalid balanceId in op: %d", operation.index)
}
details["balance_id"] = balanceID
case xdr.OperationTypeSetTrustLineFlags:
Expand Down Expand Up @@ -691,7 +691,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
fromAddress := args.ContractIdPreimage.MustFromAddress()
address, err := fromAddress.Address.String()
if err != nil {
panic(fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type))
return nil, fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type)
}
details["from"] = "address"
details["address"] = address
Expand All @@ -700,7 +700,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["from"] = "asset"
details["asset"] = args.ContractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
return nil, fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type)
}
case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2:
args := op.HostFunction.MustCreateContractV2()
Expand All @@ -709,7 +709,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
fromAddress := args.ContractIdPreimage.MustFromAddress()
address, err := fromAddress.Address.String()
if err != nil {
panic(fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type))
return nil, fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type)
}
details["from"] = "address"
details["address"] = address
Expand All @@ -718,7 +718,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["from"] = "asset"
details["asset"] = args.ContractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
return nil, fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type)
}

details["parameters"] = extractFunctionArgs(args.ConstructorArgs)
Expand All @@ -730,14 +730,14 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
}
case xdr.HostFunctionTypeHostFunctionTypeUploadContractWasm:
default:
panic(fmt.Errorf("unknown host function type: %s", op.HostFunction.Type))
return nil, fmt.Errorf("unknown host function type: %s", op.HostFunction.Type)
}
case xdr.OperationTypeExtendFootprintTtl:
op := operation.operation.Body.MustExtendFootprintTtlOp()
details["extend_to"] = op.ExtendTo
case xdr.OperationTypeRestoreFootprint:
default:
panic(fmt.Errorf("unknown operation type: %s", operation.OperationType()))
return nil, fmt.Errorf("unknown operation type: %s", operation.OperationType())
}

sponsor, err := operation.getSponsor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ impl Contract {
env.storage().instance().set(&KEY, &2_u32);
env.storage().temporary().set(&KEY, &3_u32);
}

pub fn get_data(env: Env, key: Symbol) -> u32 {
env.storage().persistent().get::<_, u32>(&key).unwrap()
+ env.storage().instance().get::<_, u32>(&key).unwrap()
+ env.storage().temporary().get::<_, u32>(&key).unwrap()
}
}
16 changes: 5 additions & 11 deletions services/horizon/internal/integration/invokehostfunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,10 @@ func TestContractInvokeHostFunctionCreateConstructorContract(t *testing.T) {
asset := xdr.MustNewCreditAsset(code, issuer)
createSAC(itest, asset)

// establish which account will be contract owner, and load it's current seq
sourceAccount, err := itest.Client().AccountDetail(horizonclient.AccountRequest{
AccountID: itest.Master().Address(),
})
require.NoError(t, err)

// Install the contract
installContractOp := assembleInstallContractCodeOp(t, itest.Master().Address(), constructor_contract)
preFlightOp, minFee := itest.PreflightHostFunctions(&sourceAccount, *installContractOp)
itest.MustSubmitOperationsWithFee(&sourceAccount, itest.Master(), minFee+txnbuild.MinBaseFee, &preFlightOp)
preFlightOp, minFee := itest.PreflightHostFunctions(itest.MasterAccount(), *installContractOp)
itest.MustSubmitOperationsWithFee(itest.MasterAccount(), itest.Master(), minFee+txnbuild.MinBaseFee, &preFlightOp)

// Create the contract
senderAddressArg := accountAddressParam(itest.Master().Address())
Expand All @@ -174,8 +168,8 @@ func TestContractInvokeHostFunctionCreateConstructorContract(t *testing.T) {
amount,
},
)
preFlightOp, minFee = itest.PreflightHostFunctions(&sourceAccount, *createContractOp)
tx, err := itest.SubmitOperationsWithFee(&sourceAccount, itest.Master(), minFee+txnbuild.MinBaseFee, &preFlightOp)
preFlightOp, minFee = itest.PreflightHostFunctions(itest.MasterAccount(), *createContractOp)
tx, err := itest.SubmitOperationsWithFee(itest.MasterAccount(), itest.Master(), minFee+txnbuild.MinBaseFee, &preFlightOp)
require.NoError(t, err)
contractID := preFlightOp.Ext.SorobanData.Resources.Footprint.ReadWrite[0].MustContractData().Contract.ContractId

Expand All @@ -202,7 +196,7 @@ func TestContractInvokeHostFunctionCreateConstructorContract(t *testing.T) {
invokeHostFunctionOpJson, ok := clientInvokeOp.Embedded.Records[0].(operations.InvokeHostFunction)
assert.True(t, ok)
assert.Equal(t, invokeHostFunctionOpJson.Function, "HostFunctionTypeHostFunctionTypeCreateContractV2")
assert.Equal(t, invokeHostFunctionOpJson.Address, sourceAccount.AccountID)
assert.Equal(t, invokeHostFunctionOpJson.Address, itest.Master().Address())
assert.Equal(t, invokeHostFunctionOpJson.Salt, "110986164698320180327942133831752629430491002266485370052238869825166557303060")

assert.Len(t, invokeHostFunctionOpJson.Parameters, 3)
Expand Down
Binary file not shown.

0 comments on commit 085899d

Please sign in to comment.