Skip to content

Commit

Permalink
chore: cleanup - comments and casing
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Apr 30, 2019
1 parent aa9a742 commit 3169ca7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
16 changes: 8 additions & 8 deletions aeternity/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func Test_buildOracleQueryID(t *testing.T) {
tests := []struct {
name string
args args
wantId string
wantID string
wantErr bool
}{
{
Expand All @@ -261,7 +261,7 @@ func Test_buildOracleQueryID(t *testing.T) {
senderNonce: uint64(3),
recipient: "ok_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi",
},
wantId: "oq_2NhMjBdKHJYnQjDbAxanmxoXiSiWDoG9bqDgk2MfK2X6AB9Bwx",
wantID: "oq_2NhMjBdKHJYnQjDbAxanmxoXiSiWDoG9bqDgk2MfK2X6AB9Bwx",
wantErr: false,
},
{
Expand All @@ -271,21 +271,21 @@ func Test_buildOracleQueryID(t *testing.T) {
senderNonce: uint64(1),
recipient: "ok_2iqfJjbhGgJFRezjX6Q6DrvokkTM5niGEHBEJZ7uAG5fSGJAw1",
},
wantId: "oq_2YvZnoohcSvbQCsPKSMxc98i5HZ1sU5mR6xwJUZC3SvkuSynMj",
wantID: "oq_2YvZnoohcSvbQCsPKSMxc98i5HZ1sU5mR6xwJUZC3SvkuSynMj",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotId, err := buildOracleQueryID(tt.args.sender, tt.args.senderNonce, tt.args.recipient)
gotID, err := buildOracleQueryID(tt.args.sender, tt.args.senderNonce, tt.args.recipient)
if (err != nil) != tt.wantErr {
t.Errorf("buildOracleQueryID() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotId != tt.wantId {
gotIdBytes, _ := Decode(gotId)
wantIdBytes, _ := Decode(tt.wantId)
t.Errorf("buildOracleQueryID() = \n%v\n%v, want \n%v\n%v", gotId, gotIdBytes, tt.wantId, wantIdBytes)
if gotID != tt.wantID {
gotIDBytes, _ := Decode(gotID)
wantIDBytes, _ := Decode(tt.wantID)
t.Errorf("buildOracleQueryID() = \n%v\n%v, want \n%v\n%v", gotID, gotIDBytes, tt.wantID, wantIDBytes)
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (n *Aens) NameUpdateTx(name string, targetAddress string) (tx NameUpdateTx,
return
}

// OracleRegisterTx create a new oracle
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee utils.BigInt, oracleTTLType, oracleTTLValue, abiVersion uint64, vmVersion uint64) (tx OracleRegisterTx, err error) {
ttl, nonce, err := getTTLNonce(o.nodeClient, o.owner.Address, Config.Client.TTL)
if err != nil {
Expand All @@ -282,6 +283,7 @@ func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee utils
return tx, nil
}

// OracleExtendTx extend the lifetime of an existing oracle
func (o *Oracle) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx OracleExtendTx, err error) {
ttl, nonce, err := getTTLNonce(o.nodeClient, o.owner.Address, Config.Client.TTL)
if err != nil {
Expand All @@ -292,6 +294,7 @@ func (o *Oracle) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx O
return tx, nil
}

// OracleQueryTx ask something of an oracle
func (o *Oracle) OracleQueryTx(OracleID, Query string, QueryFee utils.BigInt, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx OracleQueryTx, err error) {
ttl, nonce, err := getTTLNonce(o.nodeClient, o.owner.Address, Config.Client.TTL)
if err != nil {
Expand All @@ -302,6 +305,7 @@ func (o *Oracle) OracleQueryTx(OracleID, Query string, QueryFee utils.BigInt, Qu
return tx, nil
}

// OracleRespondTx the oracle responds by sending this transaction
func (o *Oracle) OracleRespondTx(OracleID string, QueryID string, Response string, TTLType uint64, TTLValue uint64) (tx OracleRespondTx, err error) {
ttl, nonce, err := getTTLNonce(o.nodeClient, o.owner.Address, Config.Client.TTL)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ type OracleRespondTx struct {
TxTTL uint64
}

// RLP returns a byte serialized representation
func (t *OracleRespondTx) RLP() (rlpRawMsg []byte, err error) {
oID, err := buildIDTag(IDTagOracle, t.OracleID)
if err != nil {
Expand All @@ -619,6 +620,7 @@ func (t *OracleRespondTx) RLP() (rlpRawMsg []byte, err error) {
return
}

// JSON representation of a Tx is useful for querying the node's debug endpoint
func (t *OracleRespondTx) JSON() (string, error) {
responseTTLTypeStr := ttlTypeIntToStr(t.ResponseTTLType)

Expand Down
77 changes: 38 additions & 39 deletions aeternity/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,44 @@ func TestSpendTx_RLP(t *testing.T) {
})
}
}
func TestNamePointer_EncodeRLP(t *testing.T) {
type fields struct {
ID string
Key string
}
tests := []struct {
name string
fields fields
wantW []byte
wantErr bool
}{
{
name: "1 pointer to a normal ak_ account",
fields: fields{
Key: "account_pubkey",
ID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v",
},
// the reference value of wantW is taken from a correct serialization of NameUpdateTx.
// Unfortunately there is no way to get the node to serialize just the NamePointer.
wantW: []byte{241, 142, 97, 99, 99, 111, 117, 110, 116, 95, 112, 117, 98, 107, 101, 121, 161, 1, 31, 19, 163, 176, 139, 240, 1, 64, 6, 98, 166, 139, 105, 216, 117, 247, 128, 60, 236, 76, 8, 100, 127, 110, 213, 216, 76, 120, 151, 189, 80, 163},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewNamePointer(tt.fields.Key, tt.fields.ID)
w := &bytes.Buffer{}
if err := p.EncodeRLP(w); (err != nil) != tt.wantErr {
t.Errorf("NamePointer.EncodeRLP() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotW := w.Bytes(); !bytes.Equal(gotW, tt.wantW) {
t.Errorf("NamePointer.EncodeRLP() = %v, want %v", gotW, tt.wantW)
fmt.Println(DecodeRLPMessage(gotW))
}
})
}
}

func TestNamePreclaimTx_RLP(t *testing.T) {
type fields struct {
Expand Down Expand Up @@ -510,45 +548,6 @@ func TestOracleQueryTx_RLP(t *testing.T) {
}
}

func TestNamePointer_EncodeRLP(t *testing.T) {
type fields struct {
ID string
Key string
}
tests := []struct {
name string
fields fields
wantW []byte
wantErr bool
}{
{
name: "1 pointer to a normal ak_ account",
fields: fields{
Key: "account_pubkey",
ID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v",
},
// the reference value of wantW is taken from a correct serialization of NameUpdateTx.
// Unfortunately there is no way to get the node to serialize just the NamePointer.
wantW: []byte{241, 142, 97, 99, 99, 111, 117, 110, 116, 95, 112, 117, 98, 107, 101, 121, 161, 1, 31, 19, 163, 176, 139, 240, 1, 64, 6, 98, 166, 139, 105, 216, 117, 247, 128, 60, 236, 76, 8, 100, 127, 110, 213, 216, 76, 120, 151, 189, 80, 163},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewNamePointer(tt.fields.Key, tt.fields.ID)
w := &bytes.Buffer{}
if err := p.EncodeRLP(w); (err != nil) != tt.wantErr {
t.Errorf("NamePointer.EncodeRLP() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotW := w.Bytes(); !bytes.Equal(gotW, tt.wantW) {
t.Errorf("NamePointer.EncodeRLP() = %v, want %v", gotW, tt.wantW)
fmt.Println(DecodeRLPMessage(gotW))
}
})
}
}

func TestOracleRespondTx_RLP(t *testing.T) {
type fields struct {
OracleID string
Expand Down

0 comments on commit 3169ca7

Please sign in to comment.