我正在尝试从打开的 zeppelin 导入一些合约文件,以便我的 Solidity 智能合约可以继承它们的功能,当尝试编写在编译时在我的智能合约上运行的 chai 测试时,我在 chai 测试中遇到错误。
3 passing (2s)
1 failing
1) Contract: Color
minting
creates a new token:
TypeError: contract.totalSupply is not a function
Run Code Online (Sandbox Code Playgroud)
我的合同导入了 openzeppelin 合同
pragma solidity 0.8.7;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; //import base functionality
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; //import totalsupply()
contract color is ERC721 {
string[] public colors;
mapping(string => bool) _colorExists; //mappings are like json objects where value a is searched and its value is returned
constructor() ERC721("Color", "COLOR") {
}
function mint(string memory _color) public{ …Run Code Online (Sandbox Code Playgroud) 我看到我的猫鼬池在插入数据之前似乎已关闭,因为在调用云集群中的猫鼬数据库时出现此错误
MongoRuntimeError: Connection pool closed
Run Code Online (Sandbox Code Playgroud)
但我正在等待所有的电话?所以我不确定为什么会看到这个问题,也许这与我定义客户的方式有关?希望有人对此有一些建议或想法
export const storeData = async (data) =>{
const uri = `mongodb+srv://plantmaster:${password}@cluster0.yey8l.mongodb.net/plantstore?retryWrites=true&w=majority`;
const client = await MongoClient.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverApi: ServerApiVersion.v1
});
const newPLantData = { name: "Company Inc", address: "Highway 37" };
await client.db("plantstore").collection("plantdata").insertOne(newPLantData, (err, res) =>{
if(err) throw err;
console.log(result)
})
await client.close();
};
Run Code Online (Sandbox Code Playgroud)
我在特快专递路线上调用此函数,如下所示
// store data
app.post('/store', async function (req, res) {
await storeData(req.body);
res.send('data was stored')
})
Run Code Online (Sandbox Code Playgroud) 我有一个父组件 (app.component) 发出 http 请求,将结果分配为 this.stats,然后将其作为 prop 传递给子组件 (progression.component)。我的问题似乎是我的孩子在从父母那里获取任何数据之前正在渲染,导致孩子抛出错误并中断。
即当我在子组件中记录 prop 时,我得到 -> {} [[Prototype]]: Object
我只是缺乏经验,但由于我的所有组件都使用 ngOnInit() 并订阅了可观察量,我认为孩子应该等待父母完成?我不确定如何修复这样的问题,因为它存在于各个组件中,并且不是我可以合并我认为的可观察量的情况......任何见解都会很棒:)谢谢!
父组件
export class AppComponent {
title = 'pctothemoon';
stats: any
constructor(private specsService: SpecsService) {}
ngOnInit(): void {
this.specsService.getStats().subscribe((res)=>{this.stats=res})
}
}
Run Code Online (Sandbox Code Playgroud)
子组件
export class ProgressionComponent {
@Input() stats: any;
oldStats: any;
constructor(private specsService: SpecsService) { }
ngOnInit(): void {
this.specsService.getProgress().subscribe((res)=>{console.log(res)})
}
AfterViewInit(){
this.specsService.postUpdates(this.stats).subscribe((res)=>{console.log("updated stats", res)})
}
}
Run Code Online (Sandbox Code Playgroud)
作为参考,我还将包含我的 service.ts 以在后台显示我的 http 请求
export class SpecsService {
private apiUrl = 'http://localhost:3000'
constructor(private http:HttpClient) …Run Code Online (Sandbox Code Playgroud)