Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Fix MemoData treated as MemoFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
wltsmrz committed May 13, 2015
1 parent f0da869 commit ffd30eb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 55 deletions.
2 changes: 1 addition & 1 deletion api/transaction/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function createPaymentTransaction(account, payment) {
if (payment.memos && Array.isArray(payment.memos)) {
for (var m = 0; m < payment.memos.length; m++) {
var memo = payment.memos[m];
transaction.addMemo(memo.MemoType, memo.MemoData);
transaction.addMemo(memo.MemoType, memo.MemoFormat, memo.MemoData);
}
}

Expand Down
141 changes: 87 additions & 54 deletions test/payments-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable new-cap */
/* eslint-disable space-in-brackets */
/* eslint-disable max-len */

'use strict';

var _ = require('lodash');
var assert = require('assert-diff');
var ripple = require('ripple-lib');
Expand Down Expand Up @@ -542,7 +545,7 @@ suite('post payments', function() {
});

self.wss.once('request_submit', function() {
assert(false);
assert(false, 'Should not request submit');
});

self.app
Expand All @@ -560,22 +563,17 @@ suite('post payments', function() {
});

test('/payments -- invalid memos', function(done) {
self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
self.wss.once('request_account_info', function() {
assert(false, 'Should not request account_info');
});

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');
conn.send(fixtures.requestSubmitResponse(message));
self.wss.once('request_submit', function() {
assert(false, 'Should not request submit');
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/payments')
.send(fixtures.payment({
memos: 'some string'
}))
.send(fixtures.payment({ memos: 'some string' }))
.expect(testutils.checkStatus(400))
.expect(testutils.checkHeaders)
.expect(testutils.checkBody(errors.RESTErrorResponse({
Expand All @@ -587,15 +585,12 @@ suite('post payments', function() {
});

test('/payments -- empty memos array', function(done) {
self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
self.wss.once('request_account_info', function() {
assert(false, 'Should not request account_info');
});

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');
conn.send(fixtures.requestSubmitResponse(message));
self.wss.once('request_submit', function() {
assert(false, 'Should not request submit');
});

self.app
Expand All @@ -614,28 +609,20 @@ suite('post payments', function() {
});

test('/payments -- memo containing a MemoType field with an int value', function(done) {
self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
self.wss.once('request_account_info', function() {
assert(false, 'Should not request account_info');
});

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');
conn.send(fixtures.requestSubmitResponse(message));
self.wss.once('request_submit', function() {
assert(false, 'Should not request submit');
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/payments')
.send(fixtures.payment({
memos: [
{
MemoType: 1,
MemoData: 'some_value'
},
{
MemoData: 'some_value'
}
{ MemoType: 1, MemoData: 'some_value' },
{ MemoData: 'some_value' }
]
}))
.expect(testutils.checkStatus(400))
Expand All @@ -649,28 +636,20 @@ suite('post payments', function() {
});

test('/payments -- memo containing a MemoData field with an int value', function(done) {
self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
self.wss.once('request_account_info', function() {
assert(false, 'Should not request account_info');
});

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');
conn.send(fixtures.requestSubmitResponse(message));
self.wss.once('request_submit', function() {
assert(false, 'Should not request submit');
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/payments')
.send(fixtures.payment({
memos: [
{
MemoType: 'some_key',
MemoData: 1
},
{
MemoData: 'some_value'
}
{ MemoType: 'some_key', MemoData: 1 },
{ MemoData: 'some_value' }
]
}))
.expect(testutils.checkStatus(400))
Expand All @@ -692,6 +671,51 @@ suite('post payments', function() {

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');

var tx_json = new ripple.SerializedObject(message.tx_blob).to_json();
var expected = [ { Memo: { MemoData: '736F6D655F76616C7565' } } ];

assert.deepEqual(tx_json.Memos, expected);
conn.send(fixtures.requestSubmitResponse(message));
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/payments')
.send(fixtures.payment({
memos: [
{ MemoData: 'some_value' }
]
}))
.expect(testutils.checkStatus(200))
.expect(testutils.checkHeaders)
.expect(testutils.checkBody(fixtures.RESTSuccessResponse()))
.end(done);
});

test('/payments -- memo with non-url-char MemoData', function(done) {
self.wss.once('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
});

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');
assert.strictEqual(typeof message.tx_blob, 'string');

var tx_json = new ripple.SerializedObject(message.tx_blob).to_json();
var expected = [{
Memo: {
MemoType: '736F6D655F74797065',
MemoData: '736F6D652064617461',
MemoFormat: '736F6D655F666F726D6174',
parsed_memo_type: 'some_type',
parsed_memo_format: 'some_format'
}}];

assert.strictEqual(typeof tx_json, 'object');
assert.deepEqual(tx_json.Memos, expected);

conn.send(fixtures.requestSubmitResponse(message));
});

Expand All @@ -700,7 +724,9 @@ suite('post payments', function() {
.send(fixtures.payment({
memos: [
{
MemoData: 'some_value'
MemoData: 'some data',
MemoType: 'some_type',
MemoFormat: 'some_format'
}
]
}))
Expand All @@ -719,20 +745,27 @@ suite('post payments', function() {

self.wss.once('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');

var tx_json = new ripple.SerializedObject(message.tx_blob).to_json();
var expected = [{
Memo: {
MemoType: '736F6D655F6B6579',
MemoData: '736F6D655F76616C7565',
parsed_memo_type: 'some_key'
}},
{ Memo: { MemoData: '736F6D655F76616C7565' } }
];

assert.deepEqual(tx_json.Memos, expected);
conn.send(fixtures.requestSubmitResponse(message));
});

self.app
.post('/v1/accounts/' + addresses.VALID + '/payments')
.send(fixtures.payment({
memos: [
{
MemoType: 'some_key',
MemoData: 'some_value'
},
{
MemoData: 'some_value'
}
{ MemoType: 'some_key', MemoData: 'some_value' },
{ MemoData: 'some_value' }
]
}))
.expect(testutils.checkStatus(200))
Expand Down

0 comments on commit ffd30eb

Please sign in to comment.