Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao committed Oct 29, 2024
1 parent f3d8c2a commit f9b77b6
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 25 deletions.
298 changes: 273 additions & 25 deletions internal/transform/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er
return
}

var wasm []byte
var contractHash xdr.Hash
var salt [32]byte
var assetCode [12]byte
var assetIssuer xdr.Uint256
contractHash := xdr.Hash{}
salt := [32]byte{}
assetCode := [12]byte{}
assetIssuer := xdr.Uint256{}
wasm := []byte{}
dummyBool := true

hardCodedClearFlags := xdr.Uint32(3)
hardCodedSetFlags := xdr.Uint32(4)
Expand Down Expand Up @@ -585,6 +586,39 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er
},
},
},
{
SourceAccount: nil,
Body: xdr.OperationBody{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionOp: &xdr.InvokeHostFunctionOp{
HostFunction: xdr.HostFunction{
Type: xdr.HostFunctionTypeHostFunctionTypeCreateContractV2,
CreateContractV2: &xdr.CreateContractArgsV2{
ContractIdPreimage: xdr.ContractIdPreimage{
Type: xdr.ContractIdPreimageTypeContractIdPreimageFromAsset,
FromAsset: &xdr.Asset{
Type: xdr.AssetTypeAssetTypeCreditAlphanum12,
AlphaNum12: &xdr.AlphaNum12{
AssetCode: assetCode,
Issuer: xdr.AccountId{
Type: xdr.PublicKeyTypePublicKeyTypeEd25519,
Ed25519: &assetIssuer,
},
},
},
},
Executable: xdr.ContractExecutable{},
ConstructorArgs: []xdr.ScVal{
{
Type: xdr.ScValTypeScvBool,
B: &dummyBool,
},
},
},
},
},
},
},
{
SourceAccount: nil,
Body: xdr.OperationBody{
Expand Down Expand Up @@ -909,12 +943,69 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er
},
},
},
{},
{},
{},
{},
{},
{},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
{
Code: xdr.OperationResultCodeOpInner,
Tr: &xdr.OperationResultTr{
Type: xdr.OperationTypeInvokeHostFunction,
InvokeHostFunctionResult: &xdr.InvokeHostFunctionResult{
Code: xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess,
},
},
},
}
inputTransaction.Result.Result.Result.Results = &results
inputTransaction.Envelope.V1 = &inputEnvelope
Expand All @@ -925,6 +1016,8 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) {
hardCodedSourceAccountAddress := testAccount3Address
hardCodedDestAccountAddress := testAccount4Address
hardCodedLedgerClose := genericCloseTime.UTC()
var nilStringArray []string

transformedOperations = []OperationOutput{
{
SourceAccount: hardCodedSourceAccountAddress,
Expand Down Expand Up @@ -1746,11 +1839,62 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) {
OperationDetails: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeInvokeContract",
"type": "invoke_contract",
"contract_id": "",
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
"contract_code_hash": "",
"asset_balance_changes": []map[string]interface{}{},
"ledger_key_hash": nilStringArray,
"parameters": []map[string]string{
{
"type": "Address",
"value": "AAAAEgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
},
{
"type": "Sym",
"value": "AAAADwAAAAR0ZXN0",
},
},
"parameters_decoded": []map[string]string{
{
"type": "Address",
"value": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
},
{
"type": "Sym",
"value": "test",
},
},
},
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
ClosedAt: hardCodedLedgerClose,
OperationDetailsJSON: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeInvokeContract",
"type": "invoke_contract",
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
"contract_code_hash": "",
"asset_balance_changes": []map[string]interface{}{},
"ledger_key_hash": nilStringArray,
"parameters": []map[string]string{
{
"type": "Address",
"value": "AAAAEgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
},
{
"type": "Sym",
"value": "AAAADwAAAAR0ZXN0",
},
},
"parameters_decoded": []map[string]string{
{
"type": "Address",
"value": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
},
{
"type": "Sym",
"value": "test",
},
},
},
ClosedAt: hardCodedLedgerClose,
},
OperationOutput{
Type: 24,
Expand All @@ -1764,9 +1908,21 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) {
"contract_id": "",
"contract_code_hash": "",
"from": "address",
"address": "",
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
OperationDetailsJSON: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeCreateContract",
"type": "create_contract",
"contract_id": "",
"contract_code_hash": "",
"from": "address",
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
},
OperationOutput{
Type: 24,
Expand All @@ -1780,49 +1936,141 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) {
"contract_id": "",
"contract_code_hash": "",
"from": "asset",
"asset": "",
"asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
"ledger_key_hash": nilStringArray,
},
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
ClosedAt: hardCodedLedgerClose,
OperationDetailsJSON: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeCreateContract",
"type": "create_contract",
"contract_id": "",
"contract_code_hash": "",
"from": "asset",
"asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
},
OperationOutput{
Type: 24,
TypeString: "invoke_host_function",
SourceAccount: hardCodedSourceAccountAddress,
TransactionID: 4096,
OperationID: 4131,
OperationDetails: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeCreateContractV2",
"type": "create_contract_v2",
"contract_id": "",
"contract_code_hash": "",
"from": "asset",
"asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
"ledger_key_hash": nilStringArray,
"parameters": []map[string]string{
{
"type": "B",
"value": "AAAAAAAAAAE=",
},
},
"parameters_decoded": []map[string]string{
{
"type": "B",
"value": "true",
},
},
},
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
ClosedAt: hardCodedLedgerClose,
OperationDetailsJSON: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeCreateContractV2",
"type": "create_contract_v2",
"contract_id": "",
"contract_code_hash": "",
"from": "asset",
"asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
"ledger_key_hash": nilStringArray,
"parameters": []map[string]string{
{
"type": "B",
"value": "AAAAAAAAAAE=",
},
},
"parameters_decoded": []map[string]string{
{
"type": "B",
"value": "true",
},
},
},
},
OperationOutput{
Type: 24,
TypeString: "invoke_host_function",
SourceAccount: hardCodedSourceAccountAddress,
TransactionID: 4096,
OperationID: 4132,
OperationDetails: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeUploadContractWasm",
"type": "upload_wasm",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
OperationDetailsJSON: map[string]interface{}{
"function": "HostFunctionTypeHostFunctionTypeUploadContractWasm",
"type": "upload_wasm",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
},
OperationOutput{
Type: 25,
TypeString: "bump_footprint_expiration",
TypeString: "extend_footprint_ttl",
SourceAccount: hardCodedSourceAccountAddress,
TransactionID: 4096,
OperationID: 4132,
OperationID: 4133,
OperationDetails: map[string]interface{}{
"type": "bump_footprint_expiration",
"ledgers_to_expire": 1234,
"type": "extend_footprint_ttl",
"extend_to": xdr.Uint32(1234),
"contract_id": "",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
OperationDetailsJSON: map[string]interface{}{
"type": "extend_footprint_ttl",
"extend_to": xdr.Uint32(1234),
"contract_id": "",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
},
OperationOutput{
Type: 26,
TypeString: "restore_footprint",
SourceAccount: hardCodedSourceAccountAddress,
TransactionID: 4096,
OperationID: 4133,
OperationID: 4134,
OperationDetails: map[string]interface{}{
"type": "restore_footprint",
"contract_id": "",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
OperationResultCode: "OperationResultCodeOpInner",
OperationTraceCode: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess",
OperationDetailsJSON: map[string]interface{}{
"type": "restore_footprint",
"contract_id": "",
"contract_code_hash": "",
"ledger_key_hash": nilStringArray,
},
ClosedAt: hardCodedLedgerClose,
},
}
return
Expand Down
Loading

0 comments on commit f9b77b6

Please sign in to comment.