1
00:00:00,210 --> 00:00:03,450
In this video, I want to write a crowdsale test.

2
00:00:03,450 --> 00:00:09,600
And I want to show you a couple of things that you will run into when you're working with tests in truffle

3
00:00:09,870 --> 00:00:11,970
and you're going to fix them, obviously.

4
00:00:12,060 --> 00:00:15,330
So first of all, we are going to write create a new file.

5
00:00:15,540 --> 00:00:26,010
My token sale, the test case and the first intuition would be just basically copy over most parts of

6
00:00:26,010 --> 00:00:28,020
our token test.

7
00:00:28,470 --> 00:00:34,320
In this case, it's going to be token sale, my token sale artifact.

8
00:00:34,320 --> 00:00:36,030
And we want to.

9
00:00:36,960 --> 00:00:42,630
You know, also get the actually the token in both of them.

10
00:00:48,720 --> 00:00:57,090
And maybe a first test would be to see if there is really no more tokens in our account and really all

11
00:00:57,090 --> 00:00:59,550
the tokens sent to the token sale.

12
00:00:59,550 --> 00:01:00,750
Smart contract.

13
00:01:01,140 --> 00:01:02,580
Let we fix this first.

14
00:01:03,810 --> 00:01:04,440
All right.

15
00:01:04,709 --> 00:01:09,450
Now, one thing that you were thinking is why I'm not copying the before each.

16
00:01:09,450 --> 00:01:14,670
Because in our token sale test, we are actually using what is in the migration file.

17
00:01:14,670 --> 00:01:19,050
So I can very much live with how this smart contract was deployed.

18
00:01:19,080 --> 00:01:25,150
There is no need to basically copy and paste this behavior into our token sale test again.

19
00:01:25,170 --> 00:01:31,320
I can just use the deployed instances of our smart contracts which get deployed through this migration

20
00:01:31,380 --> 00:01:35,040
files and then make sure that this works as expected.

21
00:01:35,490 --> 00:01:39,840
So the first thing that I'm going to test is it nope.

22
00:01:42,570 --> 00:01:51,420
It should not have any tokens in my deployed account.

23
00:02:03,170 --> 00:02:04,580
So how can we test this?

24
00:02:04,620 --> 00:02:07,280
Well, first of all, you have to get the instance

25
00:02:10,910 --> 00:02:11,660
right.

26
00:02:13,660 --> 00:02:14,550
Where is it?

27
00:02:14,660 --> 00:02:14,930
The

28
00:02:17,510 --> 00:02:19,730
token deployed?

29
00:02:20,660 --> 00:02:32,750
And then we can expect that instance, the balance of our deployer account.

30
00:02:34,890 --> 00:02:42,150
To eventually be a big number equal.

31
00:02:44,940 --> 00:02:46,260
You pick number zero.

32
00:02:48,740 --> 00:03:01,220
So just make sure that our deployer account, which is transferring all of our tokens to the token sale

33
00:03:02,060 --> 00:03:05,030
address, doesn't have any tokens anymore.

34
00:03:05,510 --> 00:03:07,550
So that would hopefully make sense.

35
00:03:07,730 --> 00:03:10,250
Now let's run this test and let's see what happens.

36
00:03:12,450 --> 00:03:14,730
We're going to compile all the smart contracts.

37
00:03:14,730 --> 00:03:20,520
It's going to deploy the smart contracts, so called clean room testing.

38
00:03:21,180 --> 00:03:24,750
And well, you see a lot of errors.

39
00:03:25,080 --> 00:03:26,190
How is that happening?

40
00:03:26,610 --> 00:03:34,860
Well, one of the problems is that we are redefining all of this above here and truffle or chai cannot

41
00:03:34,860 --> 00:03:35,520
handle it.

42
00:03:35,820 --> 00:03:39,840
So the first thing that we have to do is we would have to.

43
00:03:40,970 --> 00:03:47,370
Well, I would like to merge this into a setup because we are copying a lot of code, which is not necessary.

44
00:03:47,820 --> 00:03:54,570
The second thing is one thing that we forgot is when you have more than one test, it turns out at the

45
00:03:54,570 --> 00:04:02,010
end of all the it functions, you need to return the last test that you do like this one.

46
00:04:03,180 --> 00:04:06,870
That should already go a very long way.

47
00:04:07,170 --> 00:04:09,240
Maybe even fixes this kind of problem.

48
00:04:09,240 --> 00:04:16,829
But I still want to move all of this this header overhead into a single setup.

49
00:04:16,950 --> 00:04:21,750
Now, it doesn't fix it because it really cannot handle this.

50
00:04:24,400 --> 00:04:27,370
Let's try again just to make sure that it's really working.

51
00:04:30,890 --> 00:04:31,270
No.

52
00:04:31,670 --> 00:04:39,860
So we would have to move this part into a setup or a config or a setup chai or something function and

53
00:04:39,860 --> 00:04:40,790
then import it.

54
00:04:40,880 --> 00:04:44,120
And this is something that we are going to do in the next lecture.


