-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup: transaction unittest should not be in helpers, whose role ne…
…eds to be redefined anyway. New OracleRegisterTx unittest
- Loading branch information
1 parent
9265779
commit b5230e6
Showing
3 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,106 @@ | ||
package aeternity_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aeternity/aepp-sdk-go/aeternity" | ||
"github.com/aeternity/aepp-sdk-go/utils" | ||
) | ||
|
||
func TestSpendTx(t *testing.T) { | ||
type args struct { | ||
senderID string | ||
recipientID string | ||
amount utils.BigInt | ||
fee utils.BigInt | ||
payload string | ||
ttl uint64 | ||
nonce uint64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantTx string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Spend 10, Fee 10, Hello World", | ||
args: args{ | ||
senderID: "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi", | ||
recipientID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v", | ||
amount: *utils.NewBigIntFromUint64(10), | ||
fee: *utils.NewBigIntFromUint64(10), | ||
payload: "Hello World", | ||
ttl: uint64(10), | ||
nonce: uint64(1), | ||
}, | ||
wantTx: "tx_+FYMAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjCgoKAYtIZWxsbyBXb3JsZPSZjdM=", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotTx, err := aeternity.SpendTx(tt.args.senderID, tt.args.recipientID, tt.args.amount, tt.args.fee, tt.args.payload, tt.args.ttl, tt.args.nonce) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("SpendTx() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
gotTxStr := aeternity.Encode(aeternity.PrefixTransaction, gotTx) | ||
if gotTxStr != tt.wantTx { | ||
t.Errorf("SpendTx() = %v, want %v", gotTxStr, tt.wantTx) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOracleRegisterTx(t *testing.T) { | ||
sender := "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi" | ||
fee := utils.NewBigIntFromUint64(100) | ||
queryFee := utils.NewBigIntFromUint64(123456789) | ||
txRaw, err := aeternity.OracleRegisterTx(sender, 0, "likethis", "likethat", *queryFee, 0, 1, 0, *fee, 1) // "delta/absolute" is represented by an integer | ||
if err != nil { | ||
t.Errorf("Could not create OracleRegisterTx: %s", err) | ||
type args struct { | ||
accountID string | ||
accountNonce uint64 | ||
querySpec string | ||
responseSpec string | ||
queryFee utils.BigInt | ||
oracleTTLType uint64 | ||
oracleTTLValue uint64 | ||
abiVersion uint64 | ||
txFee utils.BigInt | ||
txTTL uint64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantTx string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "A 0 in a BigInt field shouldn't cause a RLP serialization mismatch", | ||
args: args{ | ||
accountID: "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi", | ||
accountNonce: uint64(0), | ||
querySpec: "query Specification", | ||
responseSpec: "response Specification", | ||
queryFee: *utils.NewBigIntFromUint64(0), | ||
oracleTTLType: uint64(0), | ||
oracleTTLValue: uint64(100), | ||
abiVersion: uint64(0), | ||
txFee: aeternity.Config.Client.Fee, | ||
txTTL: aeternity.Config.Client.TTL, | ||
}, | ||
wantTx: "tx_+F4WAaEBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMAk3F1ZXJ5IFNwZWNpZmljYXRpb26WcmVzcG9uc2UgU3BlY2lmaWNhdGlvbgAAZIa15iD0gACCAfQAZpU79A==", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
txRaw, err := aeternity.OracleRegisterTx(tt.args.accountID, tt.args.accountNonce, tt.args.querySpec, tt.args.responseSpec, tt.args.queryFee, tt.args.oracleTTLType, tt.args.oracleTTLValue, tt.args.abiVersion, tt.args.txFee, tt.args.txTTL) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("OracleRegisterTx() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
tx := aeternity.Encode(aeternity.PrefixTransaction, txRaw) | ||
if tx != tt.wantTx { | ||
t.Errorf("OracleRegisterTx() = %v, want %v", tx, tt.wantTx) | ||
} | ||
}) | ||
} | ||
txStr := aeternity.Encode(aeternity.PrefixTransaction, txRaw) | ||
fmt.Println(txStr) | ||
} |