To fix error in tests add followings lines of code. Example in xUnit:
Author Archives: Karol N
Using the OpenAI API in a C# console application
Repo: https://github.com/kaajoj/OpenAIApp To run it, you need to provide your own API key. Sample code with request to generate new image: https://github.com/kaajoj/OpenAIApp/blob/cc1881a985365683c90484e9cb2dca7c1361b810/OpenAIApp/OpenAI.cs#L52 Sample results of image generation: Big dogs flying a plane to Mars Dogs like top gun
New console template – use user secret
dotnet user-secrets init set a secret: dotnet user-secrets set “API_KEY” “test123” use UserSecretsId (from .csproj file) in AddUserSecrets()
Truffle test – ReferenceError: accounts is not defined
When you run command ‘truffle test’ and get error:“ReferenceError: accounts is not defined” To fix this, use below code line:contract(“Contract”, async (accounts) => {} and put test code between brackets e.g.:
Error: Number can only safely store up to 53 bits
I got this error: ‘Error: Number can only safely store up to 53 bits’ when using toNumber function: Quick fix using BigInt:
Truffle test – network error
truffle(ganache)> truffle testError: You must specify a network_id in your ‘ganache’ configuration in order to use this network. Go to config file: truffle-config.js -> uncomment ‘development’ section in ‘networks’. Change port if you have a different one in Ganache, e.g. modfiy from 8545 to 7545. Save file -> back to console -> run command: ‘truffleContinue reading “Truffle test – network error”
Create new ERC20 token – smart contract
Sample smart contract to create your own token: The same code, but with a hard-coded name, symbol and initial supply: Sources:https://docs.openzeppelin.com/contracts/4.x/erc20https://solidity-by-example.org/app/erc20/https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.0.0/contracts/token/ERC20/ERC20.sol
Problem with disabled WiFi and Unknown USB Device (Device Descriptor Request Failed)
TLDR:disable unknown USB device -> disable wifi -> hibernate -> plug off power cable -> turn on laptop –> enable wifi WiFi card: Intel(R) Wireless-AC 9560 160MHz Errors:Error (status): This device cannot start. (Code 10)Error (status): Windows has stopped this device because it has reported problems. (Code 43) When fail all methods that you tryContinue reading “Problem with disabled WiFi and Unknown USB Device (Device Descriptor Request Failed)”
Mock IConfigurate in xUnit
If you want mock IConfiguration use following code: or copy secrets.json configuration file to output directory: projectName\bin\Debug\netcoreapp3.1 and then use following code in ContextFixture: Config json file e.g. secrets.json:
Secret storage in .NET
Enable secret storage:Type “dotnet user-secrets init” into Package Manager Console <UserSecretsId> can be found in .csproj file. Set a secret (Package Manager Console):dotnet user-secrets set “ApiKey” “test123” or to remove it:dotnet user-secrets remove “ApiKey” To check if exists:dotnet user-secrets listorManage secret through GUI -> right click on project -> Manage User Secrets -> it opensContinue reading “Secret storage in .NET”