Hardhat test stuck at undefined place with TypeError: Cannot read properties of undefined 'place' - blockchain

I am developing a hardhat project, in which I was writing tests for smart contracts, and tried to run a function which recieves a bunch of arguments with different data types including struct as given below:
function createNGO(
RegDetails memory reg_details,
string memory reg_cert,
string memory act_name,
address registered_with,
string memory type_of_NGO,
string memory name_of_NGO,
SectorDetails memory sector,
FCRADetails memory FCRA,
string memory achievements,
ContactDetails memory contact_details,
string memory website_url
) external;
For testing this function, I've written a test as follows:
it("Create NGO", async () => {
const [ owner ] = await ethers.getSigners();
let args = [
[{
id: owner.address,
uid: "uid",
reg_no: "reg_no",
reg_date: 123,
pan_card: "pan_card",
addr: [{
place: "place",
city: "city",
state: "state",
pin_code: 302031
}],
is_verified: false,
is_active: true
}],
"reg_cert",
"act_name",
owner.address,
"type_of_NGO",
"name",
[{
key_issues: "key_issues",
addr: [{
place: "place",
city: "city",
state: "state",
pin_code: 302031
}]
}],
[{
is_available: true,
reg_no: 123
}],
"achievements",
[{
addr: [{
place: "place",
city: "city",
state: "state",
pin_code: 302031
}],
phone_number: [{
code: 91,
phone_number: 1234567890
}],
alt_phone_number: [{
code: 91,
phone_number: 1234567890
}],
email: "mail.com",
last_modified: 123
}],
"mywebsite.com"
]
await this.NGOContract.createNGO(...args);
console.log(await this.NGOContract.NGOs[owner]);
});
While running this test I encountered an unrelevant error, given below:
1) NGOContract
Create NGO:
TypeError: Cannot read properties of undefined (reading 'place')
at E:\Projects\Personal Projects\Charitier\server\node_modules\#ethersproject\contracts\src.ts\index.ts:152:62
at Array.map (<anonymous>)
at E:\Projects\Personal Projects\Charitier\server\node_modules\#ethersproject\contracts\src.ts\index.ts:149:44
at step (node_modules\#ethersproject\contracts\lib\index.js:48:23)
at Object.next (node_modules\#ethersproject\contracts\lib\index.js:29:53)
at E:\Projects\Personal Projects\Charitier\server\node_modules\#ethersproject\contracts\lib\index.js:23:71
at new Promise (<anonymous>)
at __awaiter (node_modules\#ethersproject\contracts\lib\index.js:19:12)
at resolveAddresses (node_modules\#ethersproject\contracts\lib\index.js:119:12)
at E:\Projects\Personal Projects\Charitier\server\node_modules\#ethersproject\contracts\src.ts\index.ts:163:22
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tried searching it on internet but found nothing.
I am using hardhat#2.12.7, ethers#5.7.0, VSCode and localhost network for development.
Suggestions are appreciated and Thanks in Advance!

Related

Amazon SP-API Listings API putListingsItem How To Update price and quantity? Node.js

I am using amazon-sp-api (JavaScript client for the Amazon Selling Partner API) but this is not limited to this client. All I want to do is use the Amazon SP-API Listings API's putListingsItem call to update the price and quantity of an item I have listed.
productType
According to the ListingsItemPutRequest docs, productType and attributes are required for this call.
Firstly, to obtain the correct productType value, you are supposed to search for a product definitions type using the Product Type Definitions API. So, I do that, and call searchDefinitionsProductTypes, just to discover my product has no matching product type.
Ultimately, I gave the value PRODUCT for productType field. Using PRODUCT, I made the getDefinitionsProductType call and got an object containing an array of propertyNames, shown below:
"propertyNames": [
"skip_offer",
"fulfillment_availability",
"map_policy",
"purchasable_offer",
"condition_type",
"condition_note",
"list_price",
"product_tax_code",
"merchant_release_date",
"merchant_shipping_group",
"max_order_quantity",
"gift_options",
"main_offer_image_locator",
"other_offer_image_locator_1",
"other_offer_image_locator_2",
"other_offer_image_locator_3",
"other_offer_image_locator_4",
"other_offer_image_locator_5"
]
},
On seeing this, I decide list_price and fulfillment_availability must be the price and quantity and then try using these in my code below.
attributes
The attributes value is also required. However, their current docs show no clear example of what to put for these values, which are where I must put price and quantity somewhere.
I found this link about patchListingsItem and tried to implement that below but got an error.
code:
// trying to update quantity... failed.
a.response = await a.sellingPartner.callAPI({
operation:'putListingsItem',
path:{
sellerId: process.env.SELLER_ID,
sku: `XXXXXXXXXXXX`
},
query: {
marketplaceIds: [ `ATVPDKIKX0DER` ]
},
body: {
"productType": `PRODUCT`
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"fulfillment_availability": {
"fulfillment_channel_code": "AMAZON_NA",
"quantity": 4,
"marketplace_id": "ATVPDKIKX0DER"
}
}
});
console.log( `a.response: `, a.response )
error:
{
"sku": "XXXXXXXXXXXX",
"status": "INVALID",
"submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
"issues": [
{
"code": "4000001",
"message": "The provided value for 'fulfillment_availability' is invalid.",
"severity": "ERROR",
"attributeName": "fulfillment_availability"
}
]
}
I also tried using list_price :
// list_price attempt... failed.
a.response = await a.sellingPartner.callAPI({
operation:'putListingsItem',
path:{
sellerId: process.env.SELLER_ID,
sku: `XXXXXXXXXXXX`
},
query: {
marketplaceIds: [ `ATVPDKIKX0DER` ]
},
body: {
"productType": `PRODUCT`
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"list_price": {
"Amount": 90,
"CurrencyCode": "USD"
}
});
console.log( `a.response: `, a.response )
Error (this time seems I got warmer... maybe?):
{
"sku": "XXXXXXXXXXXX",
"status": "INVALID",
"submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
"issues": [
{
"code": "4000001",
"message": "The provided value for 'list_price' is invalid.",
"severity": "ERROR",
"attributeName": "list_price"
}
]
}
How do you correctly specify the list_price or the quantity so this call will be successful?
Just tryin to update a single item's price and quantity.
The documentation for this side of things is terrible. I've managed to get some of it through a fair bit of trial and error though.
Fulfillment and Availability can be set with this block of JSON
"fulfillment_availability": [{
"fulfillment_channel_code": "DEFAULT",
"quantity": "9999",
"lead_time_to_ship_max_days": "5"
}]
and List price gets set, oddly, with this block. I'm still trying to find out how to set the List Price with Tax however.
"purchasable_offer": [{
"currency": "GBP",
"our_price": [{"schedule": [{"value_with_tax": 285.93}]}],
"marketplace_id": "A1F83G8C2ARO7P"
}]
Hope this helps you out :)

Correct way to persist embedded relationships in ember-data in a Ember-cli application

I am facing a situation in which I need to persist an embedded relationship into database. I am describing a similar situation in this question. It is an ember-cli project.
I have two models:
//app/model/post.js
import DS from 'ember-data';
var Post = DS.Model.extend({
entry: DS.attr('string'),
comments: DS.hasMany('comment')
});
export default Post;
//app/models/comment.js
import DS from 'ember-data';
var Comment = DS.Model.extend({
text: DS.attr('string'),
post: DS.belongsTo('post')
});
export default Comment;
1 Serializer:
//app/serializers/post.js
import DS from 'ember-data';
export default DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
comments: {
embedded: 'always'
}
}
});
1 Route:
//app/routes/index.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('post', 1);
},
setupController: function(controller, model) {
var newComment = this.store.createRecord('comment', {});
newComment.set('text', 'xxxx comment');
model.get('comments').pushObject(newComment);
model.save().then(function(){
console.log(model.toJSON());
comments = model.get('comments');
comments.forEach(function(comment){
console.log("Comment: " + comment.get('text'));
console.log("Comment id: " + comment.get('id'));
});
});
}
});
So, the GET call in model hook the server returns:
// GET /posts/1
{
"posts": {
"id": "1",
"entry": "This is first post",
"comments": [
{
"id": "1",
"post": "1",
"text": "This is the first comment on first post"
},
{
"id": "2",
"post": "1",
"text": "This is the second comment on first post"
}
]
}
}
When in the setupController hook, I add a new comment to the post and save it, its actually sending a PUT request with the following body:
// PUT /posts/1 -- Request
{
"posts": {
"id": "1",
"entry": "This is first post",
"comments": [
{
"id": "1",
"post": "1",
"text": "This is the first comment on first post"
},
{
"id": "2",
"post": "1",
"text": "This is the second comment on first post"
},
{
"post": "1",
"text": "xxxx comment"
}
]
}
}
The server returns the following output:
// PUT /posts/1 -- Response
{
"posts": {
"id": "1",
"entry": "This is first post",
"comments": [
{
"id": "1",
"post": "1",
"text": "This is the first comment on first post"
},
{
"id": "2",
"post": "1",
"text": "This is the second comment on first post"
},
{
"id": "3",
"post": "1",
"text": "xxxx comment"
}
]
}
}
But now in the console log I get the following output:
Comment: This is the first comment on first post
Comment id: 1
Comment: This is the second comment on first post
Comment id: 2
Comment: xxxx comment
Comment id: 3
Comment: xxxx comment
Comment id: null
Why is the new comment returned with id is added to the post's comments and is not replacing the comment?
Am I doing anything wrong or I need to add something else for this?
Ember Data would have no exact way of recognizing the difference between a record that user attempted to save and a record a different user attempted to save.
All it can safely know is that a new record with a new id came back (since there was no unique identifier on the record before, and you didn't specify to save that exact record).
In a non multi-user world, it could assume the new record should replace the existing record, but the Embedded Record stuff just isn't that smart yet.
1. Delete the record after you save (cause you know it'll get duped, hacky)
var comments = model.get('comments');
comments.pushObject(newComment);
model.save().then(function(){
comments.popObject(newComment);
newComment.deleteRecord(); // not really necessary
...
});
2. Save the record from the comment's point of view (cheapest and cleanest, might be a bit of additional server side logic for you)
newComment.save();

DS.store.find() using two params result in an error

i have a strange behavior:
If I call
this.store.find('uilabel', { locale: "en" });
it returns the result of /uielements?locale=en as I expect.
but if I add another parameter like
this.store.find('uilabel', { locale: "en", device: "mobile" });
I get this error:
Uncaught Error: Assertion Failed: Error: No model was found for 'device'
Ember correctly starts a GET-request to /uielements?locale=en&device=mobile which is responded
Does anyone know why this happens?
EDIT:
Here is the uilabel-model. So far, it is as primitive as it could be :)
Application.Uilabel = DS.Model.extend({
locale: DS.attr('string'),
key: DS.attr('string'),
value: DS.attr('string'),
device: DS.attr('string'),
});
EDIT2:
Sry, i could provide it by myself... here the JSON-response:
uilabels?locale=en&device=web
{
"locale": "en",
"device": "web",
"key": "server_url_dialog_default_button",
"value": "en_test"
}
Thanks
Your issue may be that the JSON response is not in the format that Ember Data is expecting. See http://emberjs.com/guides/models/connecting-to-an-http-server/. According to the spec, your JSON response needs to be in this format:
{
uilabels: [{
"locale": "en",
"device": "web",
"key": "server_url_dialog_default_button",
"value": "en_test"
}]
}
Since you're doing a this.store.find() and passing multiple parameters, Ember Data is expecting an array of results versus just a single result. Hence, it is interpreting device as an entire model, versus an attribute of uilabels.

Broken promise getting a user

I may be making a Promise faux pas but after authenticating a user I want to load the user's profile into the App.Session singleton that I've created:
App.Session.set(
'userProfile',
self.get('store').find('user',App.Session.get('userId'))
);
This results in the API call being made and a valid resultset being returned but for some reason in the debugger I get an empty result. Specifically, I do see the User.id but the rest of the columns are blank.
From the debugger, here's the JSON response:
{
"user": {
"id": "1",
"username": "jsmith",
"name": {
"first_name": "Joe",
"last_name": "Smith"
},
"emails": [
{
"id": "52153c0330063",
"name": "work-1",
"type": "other",
"address": "new#notreally.com",
"comments": "",
"status": "active",
"is_primary": false
},
{
"id": "52153d1b90ad0",
"name": "work-2",
"type": "other",
"address": "old#yesreally.com",
"comments": "",
"status": "active",
"is_primary": true
},
]
}
I'm a little new to Promises and so I thought maybe if I changed the code to:
self.get('store').find('user',App.Session.get('userId')).then( function(profile){
App.Session.set('userProfile', profile);
});
I felt pretty good about my new Promise acumen as I wrote this new code. Sadly my proud moment was greeted with failure. My second code snippet behaves precisely the same as the first one. Huh?
Can anyone help?
--------- ** UPDATE ** ---------
I've now including the model definition for User and a picture of the debugger window I made reference to.
User Model
App.RawTransform = DS.Transform.extend({
deserialize: function(serialized) {
return serialized;
},
serialize: function(deserialized) {
return deserialized;
}
});
App.NameTransform = DS.Transform.extend({
deserialize: function(serialized) {
return App.Name.create(serialized);
},
serialize: function(deserialized) {
return JSON.stringify(deserialized);
}
});
App.User = DS.Model.extend({
username: DS.attr("string"),
name: DS.attr("name"),
roles: DS.attr("raw"),
goals: DS.attr("raw"),
places: DS.attr("raw"),
emails: DS.attr("raw"),
networks: DS.attr("raw"),
relationships: DS.attr("raw"),
services: DS.attr("raw"),
uom: DS.attr("raw"),
});
Debug Window
Prior to login the model viewer looks like this:
Then after login it looks like this:
And then looking at the record details we see:
Ok, the answer seems to be down to two things. First of all, the second code snippet for handling the promise that I tried:
self.get('store').find('user',App.Session.get('userId')).then( function(profile){
App.Session.set('userProfile', profile);
});
is the correct way to go. The first method just leaves you with a "broken promise" in a "broken heart" sort of way not technically speaking but the point is it doesn't work.
The reason that my second promise implementation didn't work though was down to the Model indirectly and very specifically down to the deserializer I had put in place for Names.
I was scratching my head on this for second as the deserializer had worked back in the Ember-Data v0.1x world so I did what seemed appropriate ... I blamed Ember-Data. Come on, we've all done it. The fact is that Ember-Data had nothing to do with it and once I was willing to accept the blame I realised that it was simply a matter of not having moved my Name object over to the project I'm currently working on. Doh!

ember-data 1.0 relationships

I'm using a rest adapter with ember-data 1.0 and ember.js 1.0
given these models:
App.Customer = DS.Model.extend({
name: DS.attr('string'),
state: DS.belongsTo("State")
});
App.State = DS.Model.extend({
region: DS.attr('string'),
state: DS.attr('string'),
stateName: DS.attr('string'),
customers: DS.hasMany("Customer")
});
when I go to /#/states, I get this json response
{
"states": [
{
"region": "West",
"state": "AZ",
"stateName": "Arizona",
"id": "0x0000000000000324",
"customers": [
"0x00000000000001e5"
]
},
{
"region": "West",
"state": "CA",
"stateName": "California",
"id": "0x0000000000000325",
"customers": [
"0x00000000000001c0",
"0x00000000000001c4",
"0x00000000000001d4"
]
}
]
"customers" : [
{
}
]
}
Now, I have a couple of questions
1) What should I put in the Customers part ? A complete list of all the customers, or just a list of the customers that are specified in the state list ?
2) what data should I send back if I visit /#/customers ?
3) If I were to edit a customer. would I set it up so that the lookup/combo makes a separate request to the server ?
thanks for the help !
1) In your original JSON the customers array should only contain customers who are present in the state list.
2) This depends on your app. Generally you would want /customers to return all customers. Or maybe a paginated collection of customers. Or maybe only customers that the currently logged in user is allowed to see. Etc...
3) When you edit a customer Ember should already have the customer data loaded, so no additional lookup request should be required.