Skip to content

Commit

Permalink
feat: OracleQueryTx works. Unittest reference value taken from node, …
Browse files Browse the repository at this point in the history
…not JS SDK. Integration test updated.
  • Loading branch information
randomshinichi committed Apr 30, 2019
1 parent df5bef7 commit 24f5f87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ func (o *Oracle) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx O
return tx, nil
}

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 {
return OracleQueryTx{}, err
}

tx = NewOracleQueryTx(o.owner.Address, nonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, Config.Client.Fee, ttl)
return tx, nil
}

// StoreAccountToKeyStoreFile store an account to a json file
func StoreAccountToKeyStoreFile(account *Account, password, walletName string) (filePath string, err error) {
// keystore will be saved in current directory
Expand Down
6 changes: 3 additions & 3 deletions aeternity/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func TestOracleExtendTx_RLP(t *testing.T) {
}
}

func OracleQueryTxRLP(t *testing.T) {
func TestOracleQueryTxRLP(t *testing.T) {
type fields struct {
SenderID string
AccountNonce uint64
Expand Down Expand Up @@ -474,8 +474,8 @@ func OracleQueryTxRLP(t *testing.T) {
TxFee: Config.Client.Fee,
TxTTL: Config.Client.TTL,
},
// from aepp-sdk-js
wantTx: "tx_+GgXAaEBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMBoQTOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+841BcmUgeW91IG9rYXk/AACCASwAggEshrXmIPSAAILEzIsypOc=",
// from the node
wantTx: "tx_+GgXAaEBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMBoQTOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+841BcmUgeW91IG9rYXk/AACCASwAggEshrXmIPSAAIIB9GPfFkA=",
wantErr: false,
},
}
Expand Down
12 changes: 12 additions & 0 deletions integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ func TestOracleWorkflow(t *testing.T) {
t.Errorf("The Oracle's TTL did not change after OracleExtendTx. Got %v but expected %v", *oracle.TTL, oracleTTL)
}

fmt.Println("OracleQueryTx")
oracleQueryTx, err := aeClient.Oracle.OracleQueryTx(oraclePubKey, "How was your day?", *queryFee, 0, 100, 0, 100)
if err != nil {
t.Error(err)
}
oracleQueryTxStr, _ := aeternity.BaseEncodeTx(&oracleQueryTx)
oracleQueryTxHash, err := signBroadcast(oracleQueryTxStr, acc, aeClient)
if err != nil {
t.Error(err)
}
waitForTransaction(aeClient, oracleQueryTxHash)

}

0 comments on commit 24f5f87

Please sign in to comment.