Skip to content

Commit

Permalink
cleanup: transaction unittest should not be in helpers, whose role ne…
Browse files Browse the repository at this point in the history
…eds to be redefined anyway. New OracleRegisterTx unittest
  • Loading branch information
randomshinichi committed Mar 23, 2019
1 parent 9265779 commit b5230e6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 39 deletions.
29 changes: 0 additions & 29 deletions aeternity/helpers_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func OracleRegisterTx(accountID string, accountNonce uint64, querySpec, response
if err != nil {
return
}
qBytes := queryFee.Bytes()
// create the transaction
rlpRawMsg, err = buildRLPMessage(
ObjectTagOracleRegisterTransaction,
Expand All @@ -185,7 +186,7 @@ func OracleRegisterTx(accountID string, accountNonce uint64, querySpec, response
accountNonce,
[]byte(querySpec),
[]byte(responseSpec),
queryFee.Bytes(),
qBytes,
oracleTTLType,
oracleTTLValue,
txFee.Bytes(),
Expand Down
103 changes: 94 additions & 9 deletions aeternity/transactions_test.go
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)
}

0 comments on commit b5230e6

Please sign in to comment.