In this video, I want to write a crowdsale test.
And I want to show you a couple of things that you will run into when you're working with tests in truffle
and you're going to fix them, obviously.
So first of all, we are going to write create a new file.
My token sale, the test case and the first intuition would be just basically copy over most parts of
our token test.
In this case, it's going to be token sale, my token sale artifact.
And we want to.
You know, also get the actually the token in both of them.
And maybe a first test would be to see if there is really no more tokens in our account and really all
the tokens sent to the token sale.
Smart contract.
Let we fix this first.
All right.
Now, one thing that you were thinking is why I'm not copying the before each.
Because in our token sale test, we are actually using what is in the migration file.
So I can very much live with how this smart contract was deployed.
There is no need to basically copy and paste this behavior into our token sale test again.
I can just use the deployed instances of our smart contracts which get deployed through this migration
files and then make sure that this works as expected.
So the first thing that I'm going to test is it nope.
It should not have any tokens in my deployed account.
So how can we test this?
Well, first of all, you have to get the instance
right.
Where is it?
The
token deployed?
And then we can expect that instance, the balance of our deployer account.
To eventually be a big number equal.
You pick number zero.
So just make sure that our deployer account, which is transferring all of our tokens to the token sale
address, doesn't have any tokens anymore.
So that would hopefully make sense.
Now let's run this test and let's see what happens.
We're going to compile all the smart contracts.
It's going to deploy the smart contracts, so called clean room testing.
And well, you see a lot of errors.
How is that happening?
Well, one of the problems is that we are redefining all of this above here and truffle or chai cannot
handle it.
So the first thing that we have to do is we would have to.
Well, I would like to merge this into a setup because we are copying a lot of code, which is not necessary.
The second thing is one thing that we forgot is when you have more than one test, it turns out at the
end of all the it functions, you need to return the last test that you do like this one.
That should already go a very long way.
Maybe even fixes this kind of problem.
But I still want to move all of this this header overhead into a single setup.
Now, it doesn't fix it because it really cannot handle this.
Let's try again just to make sure that it's really working.
No.
So we would have to move this part into a setup or a config or a setup chai or something function and
then import it.
And this is something that we are going to do in the next lecture.